package com.service;

import static com.def.GenericDef.*;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import com.dao.IBisDataDao;
import com.dao.IBisOpeDao;
import com.dao.IBisPathiDao;
import com.dao.IBisToolDao;
import com.dao.IRetBoxDao;
import com.dao.IRetPrdInDao;
import com.dao.IRetPrdInfoDao;
import com.dao.IRetPrdLotDao;
import com.dao.IRetWODao;
import com.icim.service.ICIMBaseService;
import com.model.Bis_data;
import com.model.Bis_ope;
import com.model.Bis_opeId;
import com.model.Bis_pathi;
import com.model.Bis_pathiId;
import com.model.Bis_tool;
import com.model.Ret_box;
import com.model.Ret_prd_in;
import com.model.Ret_prd_info;
import com.model.Ret_prd_lot;
import com.model.Ret_prd_lotId;
import com.model.Ret_wo;
import com.rtnBean.BoxInfoBeen;
import com.rtnBean.NotFoundRtnBeen;
import com.rtnBean.SimpleRtnBeen;
import com.tx.Xpiwipeq.XpiwipeqI;
import com.tx.Xpiwipeq.XpiwipeqIA;
import com.tx.Xpiwipeq.XpiwipeqO;
import com.tx.Xpiwipeq.XpiwipeqOA;
import com.tx.Xpiwipeq.XpiwipeqOA2;
import com.util.MqOpe;
import com.util.Util;

@Scope("prototype")
@Service("XpiwipeqService")
public class XpiwipeqService extends ICIMBaseService {
    private static Logger logger = Logger.getLogger(XpiwipeqService.class);
    private static String TX_NAME = T_XPIWIPEQ;

    private XpiwipeqI inTrx;
    private XpiwipeqO outTrx;
    private MqOpe mqOpe;
    private Ret_box gRet_box;
    private Bis_ope gBis_ope;
    private Bis_opeId gBis_opeId;
    private List<Bis_data> gBis_dataL;

    @Autowired
    private IBisToolDao bisToolDao;
    @Autowired
    private IRetBoxDao retBoxDao;
    @Autowired
    private IRetPrdInfoDao retPrdInfoDao;
    @Autowired
    private IBisOpeDao bisOpeDao;
    @Autowired
    private IRetPrdInDao retPrdInDao;
    @Autowired
    private IRetPrdLotDao retPrdLotDao;
    @Autowired
    private IBisDataDao bisDataDao;
    @Autowired
    private IRetWODao retWoDao;
    @Autowired
    private IBisPathiDao bisPathiDao;

    private String gszMsgBuf = "";
    private String gproc_flg = "";

    public String subMainProc(String strInMsg) {
        Session session = retBoxDao.getCrSession();
        long rtnCode = _NORMAL;
        String outMsg = "";
        inTrx = new XpiwipeqI();
        outTrx = new XpiwipeqO();
        outTrx.setTrx_id(TX_NAME);
        outTrx.setRtn_code(String.valueOf(RETURN_CODE_SET_ERROR));
        outTrx.setType_id(TRX_OUT);
        mqOpe = new MqOpe();

        try {
            inTrx = (XpiwipeqI) mqOpe.inStr2Obj(strInMsg, inTrx);
            logger.info("InTrx is " + strInMsg);

            rtnCode = subMainProc2(inTrx.getAction_flg().toCharArray()[0]);
            if (rtnCode != _NORMAL) {
                TransactionAspectSupport.currentTransactionStatus()
                        .setRollbackOnly();
                outTrx.setRtn_code(String.valueOf(rtnCode));
                outTrx.setRtn_mesg(gszMsgBuf);
            } else {
                outTrx.setRtn_code(String.valueOf(RETURN_CODE_OK));
                outTrx.setRtn_mesg(RETURN_MESG_OK);
                session.flush();
            }
        } catch (Exception ex) {
            TransactionAspectSupport.currentTransactionStatus()
                    .setRollbackOnly();
            outTrx.setRtn_mesg(ex.toString());
            outTrx.setRtn_code(RETURN_CODE_UNKNOWN);
            logger.error(Util.stackTraceToString(ex));
        } finally {
            outMsg = mqOpe.obj2Str(outTrx);
        }
        return outMsg;
    }

    private long subMainProc2(char actionType) {
        long lRc = _NORMAL;
        lRc = queryBisData();
        if (lRc != _NORMAL) {
            return lRc;
        }


        switch (actionType) {
            case ACTION_FLG_INQUIRE: {
                lRc = getWaitBoxList();
                if (lRc != _NORMAL) {
                    return lRc;
                }
                break;
            }
            case 'S': {
                lRc = getInprPrdList();
                if (lRc != _NORMAL) {
                    return lRc;
                }
                break;
            }
            case 'B': {// 根据入账箱号获取产品信息
                lRc = getBoxAndPrdList();
                if (lRc != _NORMAL) {
                    return lRc;
                }
                break;
            }
            case 'P': {// 根据转入箱号获取 INPR 产品信息
                lRc = getInprPrdListByPrdInbox();
                if (lRc != _NORMAL) {
                    return lRc;
                }
                break;
            }
            case 'M': {// 根据来料箱号获取产品信息
                lRc = getInprPrdListByPpbox();
                if (lRc != _NORMAL) {
                    return lRc;
                }
                break;
            }
            case 'A': {// 查询在制的WAIT&INPR产品信息
                lRc = getPrdList();
                if (lRc != _NORMAL) {
                    return lRc;
                }
                break;
            }
            case 'E': {// 点击正常品，管控品或者留滞品直接保存prd_grade
                lRc = updateJudgeGrade();
                if (lRc != _NORMAL) {
                    return lRc;
                }
                break;
            }
            case 'W': {
                lRc = getPrdWipList();
                if (lRc != _NORMAL) {
                    return lRc;
                }
                break;
            }
            // 根据玻璃查询,所在箱子中的所有玻璃
            case 'C': {
                lRc = queryAllPrdListInBoxByShtId();
                if (lRc != _NORMAL) {
                    return lRc;
                }
                break;
            }
            default: {
                gszMsgBuf = "Invalide type input: [" + actionType + "]";
                return E_XPIWIPEQ_INVALID_INPUT;
            }
        }
        return lRc;
    }

    /**
     * Get box List WAIT
     *
     * @return
     */
    private long getWaitBoxList() {
        long lRc = _NORMAL;
        SimpleRtnBeen rtnBeen = new SimpleRtnBeen(_NORMAL);

        // Tool group info
        String toolGId = "";
        rtnBeen = getToolgId(inTrx.getCr_ope_id(), inTrx.getCr_ope_ver());
        if (rtnBeen.getlRc() != _NORMAL) {
            return rtnBeen.getlRc();
        } else {
            toolGId = (String) rtnBeen.getObj();
        }

        lRc = setOutBoxList2(inTrx.getBox_id(), PROC_WAIT, toolGId,
                inTrx.getWo_id(), inTrx.getLot_id());
        if (lRc != _NORMAL) {
            return lRc;
        }

        return lRc;
    }

    /**
     * Get INPR prd list
     *
     * @return
     */
    private long getInprPrdList() {
        long lRc = _NORMAL;

        // Get Pep_lvl
        Bis_ope bis_ope = new Bis_ope();
        Bis_opeId bis_opeId = new Bis_opeId();
        bis_opeId.setOpe_id(inTrx.getCr_ope_id());
        bis_opeId.setOpe_ver(inTrx.getCr_ope_ver());

        bis_ope = bisOpeDao.get(bis_opeId);
        if (null == bis_ope) {
            gszMsgBuf = new NotFoundRtnBeen(bis_opeId.toString(), Bis_ope.class)
                    .toString();
            return E_BIS_OPE + E_READ_NOT_FOUND;
        }

        // Get prd list
        List<Ret_prd_info> ret_prd_infoList = new ArrayList<Ret_prd_info>();
        String sql = "FROM Ret_prd_info WHERE   prd_stat='INPR' AND cr_ope_id_fk='"
                + inTrx.getCr_ope_id()
                + "' AND cr_ope_ver_fk = '"
                + inTrx.getCr_ope_ver() + "'";// TODO -> CR?
        if (!Util.isSpaceCheck(inTrx.getWo_id())) {
            sql = sql + " AND wo_id_fk='" + inTrx.getWo_id() + "'";
        }
        if (!Util.isSpaceCheck(inTrx.getLot_id())) {
            sql = sql + " AND lot_id='" + inTrx.getLot_id() + "'";
        }
        if (!Util.isSpaceCheck(inTrx.getPrd_id())) {
            sql = sql + " AND prd_seq_id='" + inTrx.getPrd_id() + "'";
        }
        sql = sql + " ORDER BY SLOT_NO*1 ";

        ret_prd_infoList = retPrdInfoDao.find(sql);
        outTrx.setTbl_cnt(0);
        if (!ret_prd_infoList.isEmpty()) {
            List<XpiwipeqOA2> oary_prd = new ArrayList<XpiwipeqOA2>();
            for (Ret_prd_info prd : ret_prd_infoList) {
                XpiwipeqOA2 xpiwipeqOA2 = new XpiwipeqOA2();
                xpiwipeqOA2.setPrd_seq_id(prd.getPrd_seq_id());
                xpiwipeqOA2.setSlot_no(prd.getSlot_no());
                xpiwipeqOA2.setMtrl_slot_no_fk(prd.getMtrl_slot_no_fk());
                xpiwipeqOA2.setBox_id(prd.getBox_id_fk());
                xpiwipeqOA2.setEvt_timestamp(prd.getEvt_timestamp().toString());
                xpiwipeqOA2.setEvt_user(prd.getEvt_usr());
                xpiwipeqOA2.setLot_id(prd.getLot_id());
                if (PROC_IN_PROCESS.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setPrd_grade(prd.getPrd_grade());
                } else {
                    xpiwipeqOA2.setPrd_grade(_SPACE);
                }
                xpiwipeqOA2.setCr_proc(prd.getCr_proc_id_fk());
                xpiwipeqOA2.setCr_ope_id(prd.getCr_ope_id_fk());
                xpiwipeqOA2.setCr_ope_no_fk(prd.getCr_ope_no_fk());
                xpiwipeqOA2.setCr_ope_ver_fk(prd.getCr_ope_ver_fk());
                xpiwipeqOA2.setCr_path_id_fk(prd.getCr_path_id_fk());
                xpiwipeqOA2.setCr_path_ver_fk(prd.getCr_path_ver_fk());
                xpiwipeqOA2.setCr_tool_id_fk(prd.getCr_tool_id_fk());
                xpiwipeqOA2.setFab_sn(prd.getFab_sn());
                xpiwipeqOA2.setPep_lvl(bis_ope.getPep_lvl());
                xpiwipeqOA2.setWo_id(prd.getWo_id_fk());
                xpiwipeqOA2.setMdl_id_fk(prd.getMdl_id_fk());
                xpiwipeqOA2.setPrd_qty(prd.getPrd_qty());
                xpiwipeqOA2.setPrd_std_qty(prd.getPrd_std_qty());
                xpiwipeqOA2.setSht_ope_msg(prd.getSht_ope_msg());
                xpiwipeqOA2.setMtrl_box_id_fk(prd.getMtrl_box_id_fk());
                xpiwipeqOA2.setPv_box_id_fk(prd.getPv_box_id_fk());
                xpiwipeqOA2.setPrd_stat(prd.getPrd_stat());
                xpiwipeqOA2.setX_axis_cnt_fk(prd.getX_axis_cnt_fk());
                xpiwipeqOA2.setY_axis_cnt_fk(prd.getY_axis_cnt_fk());
                xpiwipeqOA2.setPv_prd_grade(prd.getPv_prd_grade());
                xpiwipeqOA2.setGroup_id(prd.getGroup_id());
                if (!Util.isSpaceCheck(gproc_flg)) {
                    xpiwipeqOA2.setProc_flg(gproc_flg);
                }
                //增加返工品标识
                if (!Util.isSpaceCheck(prd.getOqc_skip_flg())) {
                    xpiwipeqOA2.setOqc_skip_flg(prd.getOqc_skip_flg());
                }

                if (null != prd.getT_rubbing_time()) {
                    xpiwipeqOA2.setTft_buff_time(prd.getT_rubbing_time()
                            .toString());
                }
                if (null != prd.getC_rubbing_time()) {
                    xpiwipeqOA2.setCf_buff_time(prd.getC_rubbing_time()
                            .toString());
                }

                if (prd.getP1_timestamp() != null) {
                    xpiwipeqOA2.setStart_time(prd.getP1_timestamp());

                    xpiwipeqOA2.setProcess_user(prd.getEvt_usr());
                    if (prd.getP2_timestamp() != null) {
                        xpiwipeqOA2.setEnd_time(prd.getP2_timestamp());
                    }
                }

                if (prd.getLogon_timestamp() != null) {
                    xpiwipeqOA2.setLogon_usr(prd.getLogon_usr());
                    xpiwipeqOA2.setLogon_timestamp(prd.getLogon_timestamp());
                }
                if (prd.getLogof_timestamp() != null) {
                    xpiwipeqOA2.setLogof_usr(prd.getLogof_usr());
                    xpiwipeqOA2.setLogof_timestamp(prd.getLogof_timestamp());
                }

                oary_prd.add(xpiwipeqOA2);
            }
            outTrx.setOary_prd(oary_prd);
            outTrx.setTbl_cnt(oary_prd.size());
        }

        return lRc;
    }

    private long setOutBoxList2(String box_id, String box_stat,
                                String nx_toolg_id_fk, String wo_id, String lot_id_fk) {
        long lRc = _NORMAL;
        outTrx.setTbl_cnt(0);
        List<XpiwipeqOA> oaryList = new ArrayList<XpiwipeqOA>();
        List<BoxInfoBeen> boxInfoBeenList = new ArrayList<BoxInfoBeen>();

        boxInfoBeenList = retBoxDao.retBox2BoxInfoByManyCondition(box_id,
                box_stat, nx_toolg_id_fk, wo_id, lot_id_fk);
        if (!boxInfoBeenList.isEmpty()) {
            for (BoxInfoBeen box : boxInfoBeenList) {
                //增加厂别及线别的判定
                List<Ret_prd_info> ret_prd_infoList = new ArrayList<Ret_prd_info>();
                String sql = "FROM Ret_prd_info WHERE  prd_stat='WAIT' AND box_id_fk='" + box.getBox_id() + "'";
                ret_prd_infoList = retPrdInfoDao.find(sql);
                if (ret_prd_infoList.isEmpty()) {
                    continue;
                }
                XpiwipeqOA xpiwipeqOA = new XpiwipeqOA();
                xpiwipeqOA.setBox_id(box.getBox_id());
                xpiwipeqOA.setBatch_no(box.getBatch_no_fk());
                xpiwipeqOA.setMdl_id(box.getMdl_id_fk());
                xpiwipeqOA.setOpe_id(box.getNx_ope_id_fk());
                xpiwipeqOA.setPath_id(box.getNx_path_id_fk());
                xpiwipeqOA.setPriority(box.getPrty());
                xpiwipeqOA.setQty(Integer.toString(box.getPrd_qty()));
                xpiwipeqOA.setWo_id(box.getWo_id());
                xpiwipeqOA.setPrd_grade(box.getPrd_grade_fk());
                xpiwipeqOA.setLot_id(box.getLot_id());
                xpiwipeqOA.setMode_cnt(box.getMode_cnt());
                xpiwipeqOA.setMtrl_prod_id(box.getMtrl_prod_id());
                xpiwipeqOA.setFm_mdl_id_fk(box.getFm_mdl_id_fk());
                xpiwipeqOA.setCut_mdl_id_fk(box.getCut_mdl_id_fk());
                xpiwipeqOA.setFrom_thickness(box.getFrom_thickness());
                xpiwipeqOA.setTo_thickness(box.getTo_thickness());
                xpiwipeqOA.setOk_grade_cnt(box.getOk_cnt());
                xpiwipeqOA.setNg_grade_cnt(box.getNg_cnt());
                xpiwipeqOA.setGk_grade_cnt(box.getGk_cnt());
                xpiwipeqOA.setLz_grade_cnt(box.getLz_cnt());

                if (!Util.isSpaceCheck(box.getEvt_cate())
                        && box.getEvt_cate().equals(EVT_JUMP_OPE)) {
                    xpiwipeqOA.setIsJumpOpe(_YES);
                } else {
                    xpiwipeqOA.setIsJumpOpe(_NO);
                }
                oaryList.add(xpiwipeqOA);
            }

            outTrx.setOary(oaryList);
            outTrx.setTbl_cnt(oaryList.size());
        }

        return lRc;
    }

    /**
     * Get tool group info by tool id
     *
     * @param ope_id
     * @param ope_ver
     * @return SimpleRtnBeen {String}
     */
    private SimpleRtnBeen getToolgId(String ope_id, String ope_ver) {
        Bis_ope bis_ope = new Bis_ope();
        Bis_opeId bis_opeId = new Bis_opeId();
        bis_opeId.setOpe_id(ope_id);
        bis_opeId.setOpe_ver(ope_ver);

        bis_ope = bisOpeDao.get(bis_opeId);
        if (bis_ope == null) {
            gszMsgBuf = new NotFoundRtnBeen(bis_opeId.toString(), Bis_ope.class)
                    .toString();
            return new SimpleRtnBeen(E_BIS_TOOL_GR + E_READ_NOT_FOUND);
        }

        return new SimpleRtnBeen(bis_ope.getToolg_id());
    }

    /**
     * Get box and prd Info
     *
     * @return
     */
    private long getBoxAndPrdList() {
        long lRc = _NORMAL;
        lRc = getBoxList();
        if (lRc != _NORMAL) {
            return lRc;
        }

        lRc = getInprPrdListByBox();
        if (lRc != _NORMAL) {
            return lRc;
        }

        return lRc;
    }

    /**
     * Get box Info
     *
     * @return
     */
    private long getBoxList() {
        long lRc = _NORMAL;
        List<XpiwipeqOA> oaryList = new ArrayList<XpiwipeqOA>();
        gRet_box = new Ret_box();
        gRet_box = retBoxDao.get(inTrx.getBox_id());
        if (gRet_box == null) {
            gszMsgBuf = new NotFoundRtnBeen(inTrx.getBox_id(), Ret_box.class)
                    .toString();
            return E_RET_BOX + E_READ_NOT_FOUND;
        }
        // Get intrx ope info
        gBis_ope = new Bis_ope();
        gBis_opeId = new Bis_opeId();
        gBis_opeId.setOpe_id(inTrx.getCr_ope_id());
        gBis_opeId.setOpe_ver(inTrx.getCr_ope_ver());

        gBis_ope = bisOpeDao.get(gBis_opeId);
        if (null == gBis_ope) {
            gszMsgBuf = new NotFoundRtnBeen(gBis_opeId.toString(),
                    Bis_ope.class).toString();
            return E_BIS_OPE + E_READ_NOT_FOUND;
        }
        if (!PROC_WAIT.equals(gRet_box.getBox_stat())
                && !PROC_EMPTY.equals(gRet_box.getBox_stat())) {
            gszMsgBuf = "箱子的状态[" + gRet_box.getBox_stat()
                    + "]不正确,必须为等待入账或者已入账状态,请确认！";
            return E_XPIWIPEQ_INVALID_BOX_STAT;
        }
        if (!Util.isSpaceCheck(gRet_box.getNx_ope_id_fk())
                && !Util.isSpaceCheck(gRet_box.getNx_ope_ver_fk())
                && PROC_WAIT.equals(gRet_box.getBox_stat())) {
            // Get box ope info
            Bis_ope bis_ope = new Bis_ope();
            Bis_opeId bis_opeId = new Bis_opeId();
            bis_opeId.setOpe_id(gRet_box.getNx_ope_id_fk());
            bis_opeId.setOpe_ver(gRet_box.getNx_ope_ver_fk());

            bis_ope = bisOpeDao.get(bis_opeId);
            if (null == bis_ope) {
                gszMsgBuf = new NotFoundRtnBeen(bis_opeId.toString(),
                        Bis_ope.class).toString();
                return E_BIS_OPE + E_READ_NOT_FOUND;
            }
            if (!gRet_box.getNx_ope_id_fk().equals(inTrx.getCr_ope_id())
                    || !gRet_box.getNx_ope_ver_fk().equals(
                    inTrx.getCr_ope_ver())) {
                gszMsgBuf = "箱子下一制程为[" + bis_ope.getOpe_dsc() + "],请确认！";
                return E_XPIWIPEQ_INVALID_NX_PROCESS;
            }
        }
        XpiwipeqOA xpiwipeqOA = new XpiwipeqOA();
        xpiwipeqOA.setBox_id(gRet_box.getBox_id());
        xpiwipeqOA.setBox_stat(gRet_box.getBox_stat());
        xpiwipeqOA.setOpe_id(gRet_box.getNx_ope_id_fk());
        xpiwipeqOA.setOpe_ver(gRet_box.getNx_ope_ver_fk());
        if (!Util.isSpaceCheck(gRet_box.getEvt_cate())
                && gRet_box.getEvt_cate().equals(EVT_JUMP_OPE)) {
            xpiwipeqOA.setIsJumpOpe(_YES);
        } else {
            xpiwipeqOA.setIsJumpOpe(_NO);
        }
        oaryList.add(xpiwipeqOA);
        outTrx.setOary(oaryList);
        return lRc;
    }

    /**
     * Get prd Info
     *
     * @return
     */
    private long getInprPrdListByBox() {
        long lRc = _NORMAL;
        outTrx.setTbl_cnt(0);

        List<Ret_prd_info> ret_prd_infoList = new ArrayList<Ret_prd_info>();
        String sql = "FROM Ret_prd_info WHERE ((prd_stat='INPR' AND cr_ope_id_fk='"
                + inTrx.getCr_ope_id()
                + "' AND cr_ope_ver_fk = '"
                + inTrx.getCr_ope_ver()
                + "' AND pv_box_id_fk='" + inTrx.getBox_id()
                + "') or (prd_stat='WAIT' AND nx_ope_id_fk='"
                + inTrx.getCr_ope_id()
                + "' AND nx_ope_ver_fk = '"
                + inTrx.getCr_ope_ver()
                + "' AND box_id_fk='" + inTrx.getBox_id() + "'))";
        sql = sql + " ORDER BY box_id_fk,pv_box_id_fk, convert(slot_no,UNSIGNED) ";
        ret_prd_infoList = retPrdInfoDao.find(sql);
        if (!ret_prd_infoList.isEmpty()) {
            List<XpiwipeqOA2> oary_prd = new ArrayList<XpiwipeqOA2>();
            for (Ret_prd_info prd : ret_prd_infoList) {
                XpiwipeqOA2 xpiwipeqOA2 = new XpiwipeqOA2();
                Ret_wo ret_wo = retWoDao.get(prd.getWo_id_fk());
                if (ret_wo == null) {
                    xpiwipeqOA2.setCus_id("");
                } else {
                    xpiwipeqOA2.setCus_id(ret_wo.getCus_id_fk());
                }
                xpiwipeqOA2.setPrd_seq_id(prd.getPrd_seq_id());
                xpiwipeqOA2.setSlot_no(prd.getSlot_no());
                xpiwipeqOA2.setMtrl_slot_no_fk(prd.getMtrl_slot_no_fk());
                xpiwipeqOA2.setEvt_timestamp(prd.getEvt_timestamp().toString());
                xpiwipeqOA2.setEvt_user(prd.getEvt_usr());
                xpiwipeqOA2.setLot_id(prd.getLot_id());
                if (PROC_IN_PROCESS.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setPrd_grade(prd.getPrd_grade());
                } else {
                    xpiwipeqOA2.setPrd_grade(_SPACE);
                }
                xpiwipeqOA2.setCr_proc(prd.getCr_proc_id_fk());
                xpiwipeqOA2.setCr_ope_id(prd.getCr_ope_id_fk());
                xpiwipeqOA2.setCr_ope_no_fk(prd.getCr_ope_no_fk());
                xpiwipeqOA2.setCr_ope_ver_fk(prd.getCr_ope_ver_fk());
                xpiwipeqOA2.setCr_path_id_fk(prd.getCr_path_id_fk());
                xpiwipeqOA2.setCr_path_ver_fk(prd.getCr_path_ver_fk());
                xpiwipeqOA2.setCr_tool_id_fk(prd.getCr_tool_id_fk());
                xpiwipeqOA2.setFab_sn(prd.getFab_sn());
                xpiwipeqOA2.setPep_lvl(gBis_ope.getPep_lvl());
                xpiwipeqOA2.setWo_id(prd.getWo_id_fk());
                xpiwipeqOA2.setMdl_id_fk(prd.getMdl_id_fk());
                xpiwipeqOA2.setPrd_qty(prd.getPrd_qty());
                xpiwipeqOA2.setPrd_std_qty(prd.getPrd_std_qty());
                xpiwipeqOA2.setSht_ope_msg(prd.getSht_ope_msg());
                xpiwipeqOA2.setMtrl_box_id_fk(prd.getMtrl_box_id_fk());
                xpiwipeqOA2.setPrd_stat(prd.getPrd_stat());
                xpiwipeqOA2.setPv_prd_grade(prd.getPv_prd_grade());
                xpiwipeqOA2.setDs_recipe_id(prd.getDs_recipe_id());
                xpiwipeqOA2.setGroup_id(prd.getGroup_id());
                if (!Util.isSpaceCheck(gproc_flg)) {
                    xpiwipeqOA2.setProc_flg(gproc_flg);
                }
                //增加返工品标识
                if (!Util.isSpaceCheck(prd.getOqc_skip_flg())) {
                    xpiwipeqOA2.setOqc_skip_flg(prd.getOqc_skip_flg());
                }


                xpiwipeqOA2.setPrd_admin_flg(prd.getPrd_admin_flg());
                if (null != prd.getPrd_admin_flg()) {
                    StringBuffer prd_admin_flg_sb = new StringBuffer(prd.getPrd_admin_flg());
                    String ipqc_flg = "OK";
                    String th_judge_flg = "OK";
                    String fz_flg = "OK";
                    if (prd_admin_flg_sb.charAt(1) == 'Y') {
                        ipqc_flg = "NG";
                    } else if (prd_admin_flg_sb.charAt(1) == 'N') {
                        ipqc_flg = "OK";
                    } else if (prd_admin_flg_sb.charAt(1) == 'S') {
                        ipqc_flg = "SC";
                    } else {
                        ipqc_flg = "";
                    }
                    if (prd_admin_flg_sb.charAt(2) == 'Y') {
                        th_judge_flg = "NG";
                    } else if (prd_admin_flg_sb.charAt(2) == 'N') {
                        th_judge_flg = "OK";
                    } else {
                        th_judge_flg = "";
                    }
                    if (prd_admin_flg_sb.charAt(3) == 'Y') {
                        fz_flg = "NG";
                    } else if (prd_admin_flg_sb.charAt(3) == 'N') {
                        fz_flg = "OK";
                    } else {
                        fz_flg = "";
                    }
                    xpiwipeqOA2.setIpqc_flg(ipqc_flg);
                    xpiwipeqOA2.setTh_judge_flg(th_judge_flg);
                    xpiwipeqOA2.setFz_flg(fz_flg);
                } else {
                    xpiwipeqOA2.setIpqc_flg("");
                    xpiwipeqOA2.setTh_judge_flg("");
                    xpiwipeqOA2.setFz_flg("");
                }


                if (PROC_IN_PROCESS.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setBox_id(prd.getBox_id_fk());
                    xpiwipeqOA2.setPv_box_id_fk(prd.getPv_box_id_fk());
                } else if (PROC_WAIT.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setBox_id("");
                    xpiwipeqOA2.setPv_box_id_fk(prd.getBox_id_fk());
                }
                xpiwipeqOA2.setX_axis_cnt_fk(prd.getX_axis_cnt_fk());
                xpiwipeqOA2.setY_axis_cnt_fk(prd.getY_axis_cnt_fk());
                if (null != prd.getT_rubbing_time()) {
                    xpiwipeqOA2.setTft_buff_time(prd.getT_rubbing_time()
                            .toString());
                }
                if (null != prd.getC_rubbing_time()) {
                    xpiwipeqOA2.setCf_buff_time(prd.getC_rubbing_time()
                            .toString());
                }

                if (prd.getP1_timestamp() != null && PROC_IN_PROCESS.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setStart_time(prd.getP1_timestamp());

                    xpiwipeqOA2.setProcess_user(prd.getEvt_usr());
                    if (prd.getP2_timestamp() != null) {
                        xpiwipeqOA2.setEnd_time(prd.getP2_timestamp());
                    }
                }

                if (prd.getLogon_timestamp() != null && PROC_IN_PROCESS.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setLogon_usr(prd.getLogon_usr());
                    xpiwipeqOA2.setLogon_timestamp(prd.getLogon_timestamp());
                }
                if (prd.getLogof_timestamp() != null) {
                    xpiwipeqOA2.setLogof_usr(prd.getLogof_usr());
                    xpiwipeqOA2.setLogof_timestamp(prd.getLogof_timestamp());
                }

                oary_prd.add(xpiwipeqOA2);
            }
            outTrx.setOary_prd(oary_prd);
            outTrx.setTbl_cnt(oary_prd.size());
        } else if (PROC_EMPTY.equals(gRet_box.getBox_stat())) {
            gszMsgBuf = "入账箱号在当前站点[" + gBis_ope.getOpe_dsc() + "]未找到WIP信息,请确认！";
            return E_XPIWIPEQ_NO_WIP;
        }
        return lRc;
    }

    /**
     * 根据转入箱号获取 INPR 产品信息
     *
     * @return
     */
    private long getInprPrdListByPrdInbox() {
        long lRc = _NORMAL;

        // Get Pep_lvl
        Bis_ope bis_ope = new Bis_ope();
        Bis_opeId bis_opeId = new Bis_opeId();
        bis_opeId.setOpe_id(inTrx.getCr_ope_id());
        bis_opeId.setOpe_ver(inTrx.getCr_ope_ver());

        bis_ope = bisOpeDao.get(bis_opeId);
        if (null == bis_ope) {
            gszMsgBuf = new NotFoundRtnBeen(bis_opeId.toString(), Bis_ope.class)
                    .toString();
            return E_BIS_OPE + E_READ_NOT_FOUND;
        }

        // Get prd list
        List<Ret_prd_info> ret_prd_infoList = new ArrayList<Ret_prd_info>();
        String sql = "FROM Ret_prd_info WHERE  prd_stat='INPR' AND cr_ope_id_fk='"
                + inTrx.getCr_ope_id()
                + "' AND cr_ope_ver_fk = '"
                + inTrx.getCr_ope_ver() + "'";
        if (!Util.isSpaceCheck(inTrx.getBox_id())) {
            sql = sql + " AND box_id_fk='" + inTrx.getBox_id() + "'";
        }
        sql = sql + " ORDER BY box_id_fk,pv_box_id_fk, convert(slot_no,UNSIGNED) ";

        ret_prd_infoList = retPrdInfoDao.find(sql);
        outTrx.setTbl_cnt(0);
        if (!ret_prd_infoList.isEmpty()) {
            List<XpiwipeqOA2> oary_prd = new ArrayList<XpiwipeqOA2>();
            for (Ret_prd_info prd : ret_prd_infoList) {
                XpiwipeqOA2 xpiwipeqOA2 = new XpiwipeqOA2();
                xpiwipeqOA2.setPrd_seq_id(prd.getPrd_seq_id());
                xpiwipeqOA2.setSlot_no(prd.getSlot_no());
                xpiwipeqOA2.setMtrl_slot_no_fk(prd.getMtrl_slot_no_fk());
                xpiwipeqOA2.setBox_id(prd.getBox_id_fk());
                xpiwipeqOA2.setEvt_timestamp(prd.getEvt_timestamp().toString());
                xpiwipeqOA2.setEvt_user(prd.getEvt_usr());
                xpiwipeqOA2.setLot_id(prd.getLot_id());
                if (PROC_IN_PROCESS.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setPrd_grade(prd.getPrd_grade());
                } else {
                    xpiwipeqOA2.setPrd_grade(_SPACE);
                }
                xpiwipeqOA2.setCr_proc(prd.getCr_proc_id_fk());
                xpiwipeqOA2.setCr_ope_id(prd.getCr_ope_id_fk());
                xpiwipeqOA2.setCr_ope_no_fk(prd.getCr_ope_no_fk());
                xpiwipeqOA2.setCr_ope_ver_fk(prd.getCr_ope_ver_fk());
                xpiwipeqOA2.setCr_path_id_fk(prd.getCr_path_id_fk());
                xpiwipeqOA2.setCr_path_ver_fk(prd.getCr_path_ver_fk());
                xpiwipeqOA2.setCr_tool_id_fk(prd.getCr_tool_id_fk());
                xpiwipeqOA2.setFab_sn(prd.getFab_sn());
                xpiwipeqOA2.setPep_lvl(bis_ope.getPep_lvl());
                xpiwipeqOA2.setWo_id(prd.getWo_id_fk());
                xpiwipeqOA2.setMdl_id_fk(prd.getMdl_id_fk());
                xpiwipeqOA2.setPrd_qty(prd.getPrd_qty());
                xpiwipeqOA2.setPrd_std_qty(prd.getPrd_std_qty());
                xpiwipeqOA2.setSht_ope_msg(prd.getSht_ope_msg());
                xpiwipeqOA2.setMtrl_box_id_fk(prd.getMtrl_box_id_fk());
                xpiwipeqOA2.setPv_box_id_fk(prd.getPv_box_id_fk());
                xpiwipeqOA2.setPrd_stat(prd.getPrd_stat());
                xpiwipeqOA2.setX_axis_cnt_fk(prd.getX_axis_cnt_fk());
                xpiwipeqOA2.setY_axis_cnt_fk(prd.getY_axis_cnt_fk());
                xpiwipeqOA2.setPv_prd_grade(prd.getPv_prd_grade());
                xpiwipeqOA2.setGroup_id(prd.getGroup_id());
                if (!Util.isSpaceCheck(gproc_flg)) {
                    xpiwipeqOA2.setProc_flg(gproc_flg);
                }
                //增加返工品标识
                if (!Util.isSpaceCheck(prd.getOqc_skip_flg())) {
                    xpiwipeqOA2.setOqc_skip_flg(prd.getOqc_skip_flg());
                }

                if (null != prd.getPrd_admin_flg()) {
                    StringBuffer prd_admin_flg_sb = new StringBuffer(prd.getPrd_admin_flg());
                    String ipqc_flg = "OK";
                    String th_judge_flg = "OK";
                    String fz_flg = "OK";
                    if (prd_admin_flg_sb.charAt(1) == 'Y') {
                        ipqc_flg = "NG";
                    } else if (prd_admin_flg_sb.charAt(1) == 'N') {
                        ipqc_flg = "OK";
                    } else if (prd_admin_flg_sb.charAt(1) == 'S') {
                        ipqc_flg = "SC";
                    } else {
                        ipqc_flg = "";
                    }
                    if (prd_admin_flg_sb.charAt(2) == 'Y') {
                        th_judge_flg = "NG";
                    } else if (prd_admin_flg_sb.charAt(2) == 'N') {
                        th_judge_flg = "OK";
                    } else {
                        th_judge_flg = "";
                    }
                    if (prd_admin_flg_sb.charAt(3) == 'Y') {
                        fz_flg = "NG";
                    } else if (prd_admin_flg_sb.charAt(3) == 'N') {
                        fz_flg = "OK";
                    } else {
                        fz_flg = "";
                    }
                    xpiwipeqOA2.setIpqc_flg(ipqc_flg);
                    xpiwipeqOA2.setTh_judge_flg(th_judge_flg);
                    xpiwipeqOA2.setFz_flg(fz_flg);
                } else {
                    xpiwipeqOA2.setIpqc_flg("");
                    xpiwipeqOA2.setTh_judge_flg("");
                    xpiwipeqOA2.setFz_flg("");
                }

                if (null != prd.getT_rubbing_time()) {
                    xpiwipeqOA2.setTft_buff_time(prd.getT_rubbing_time()
                            .toString());
                }
                if (null != prd.getC_rubbing_time()) {
                    xpiwipeqOA2.setCf_buff_time(prd.getC_rubbing_time()
                            .toString());
                }

                if (prd.getP1_timestamp() != null) {
                    xpiwipeqOA2.setStart_time(prd.getP1_timestamp());

                    xpiwipeqOA2.setProcess_user(prd.getEvt_usr());
                    if (prd.getP2_timestamp() != null) {
                        xpiwipeqOA2.setEnd_time(prd.getP2_timestamp());
                    }
                }
                if (prd.getLogon_timestamp() != null) {
                    xpiwipeqOA2.setLogon_usr(prd.getLogon_usr());
                    xpiwipeqOA2.setLogon_timestamp(prd.getLogon_timestamp());
                }
                if (prd.getLogof_timestamp() != null) {
                    xpiwipeqOA2.setLogof_usr(prd.getLogof_usr());
                    xpiwipeqOA2.setLogof_timestamp(prd.getLogof_timestamp());
                }
                oary_prd.add(xpiwipeqOA2);
            }
            outTrx.setOary_prd(oary_prd);
            outTrx.setTbl_cnt(oary_prd.size());
        }
        return lRc;
    }

    /**
     * 根据来料箱号获取 INPR 产品信息
     *
     * @return
     */
    private long getInprPrdListByPpbox() {
        long lRc = _NORMAL;

        // Get Pep_lvl
        Bis_ope bis_ope = new Bis_ope();
        Bis_opeId bis_opeId = new Bis_opeId();
        bis_opeId.setOpe_id(inTrx.getCr_ope_id());
        bis_opeId.setOpe_ver(inTrx.getCr_ope_ver());

        bis_ope = bisOpeDao.get(bis_opeId);
        if (null == bis_ope) {
            gszMsgBuf = new NotFoundRtnBeen(bis_opeId.toString(), Bis_ope.class)
                    .toString();
            return E_BIS_OPE + E_READ_NOT_FOUND;
        }

        // Get prd list
        List<Ret_prd_info> ret_prd_infoList = new ArrayList<Ret_prd_info>();
        String sql = "FROM Ret_prd_info WHERE ((prd_stat='INPR' AND cr_ope_id_fk='"
                + inTrx.getCr_ope_id()
                + "' AND cr_ope_ver_fk = '"
                + inTrx.getCr_ope_ver()
                + "') or (prd_stat='WAIT' AND nx_ope_id_fk='"
                + inTrx.getCr_ope_id()
                + "' AND nx_ope_ver_fk = '"
                + inTrx.getCr_ope_ver() + "'))";
        if (!Util.isSpaceCheck(inTrx.getBox_id())) {
            sql = sql + " AND mtrl_box_id_fk='" + inTrx.getBox_id() + "'";
        }
        sql = sql + " ORDER BY box_id_fk,pv_box_id_fk, convert(slot_no,UNSIGNED) ";

        ret_prd_infoList = retPrdInfoDao.find(sql);
        outTrx.setTbl_cnt(0);
        if (!ret_prd_infoList.isEmpty()) {
            List<XpiwipeqOA2> oary_prd = new ArrayList<XpiwipeqOA2>();
            for (Ret_prd_info prd : ret_prd_infoList) {
                XpiwipeqOA2 xpiwipeqOA2 = new XpiwipeqOA2();
                xpiwipeqOA2.setPrd_seq_id(prd.getPrd_seq_id());
                xpiwipeqOA2.setSlot_no(prd.getSlot_no());
                xpiwipeqOA2.setMtrl_slot_no_fk(prd.getMtrl_slot_no_fk());
                xpiwipeqOA2.setEvt_timestamp(prd.getEvt_timestamp().toString());
                xpiwipeqOA2.setEvt_user(prd.getEvt_usr());
                xpiwipeqOA2.setLot_id(prd.getLot_id());
                if (PROC_IN_PROCESS.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setPrd_grade(prd.getPrd_grade());
                } else {
                    xpiwipeqOA2.setPrd_grade(_SPACE);
                }
                xpiwipeqOA2.setCr_proc(prd.getCr_proc_id_fk());
                xpiwipeqOA2.setCr_ope_id(prd.getCr_ope_id_fk());
                xpiwipeqOA2.setCr_ope_no_fk(prd.getCr_ope_no_fk());
                xpiwipeqOA2.setCr_ope_ver_fk(prd.getCr_ope_ver_fk());
                xpiwipeqOA2.setCr_path_id_fk(prd.getCr_path_id_fk());
                xpiwipeqOA2.setCr_path_ver_fk(prd.getCr_path_ver_fk());
                xpiwipeqOA2.setCr_tool_id_fk(prd.getCr_tool_id_fk());
                xpiwipeqOA2.setFab_sn(prd.getFab_sn());
                xpiwipeqOA2.setPep_lvl(bis_ope.getPep_lvl());
                xpiwipeqOA2.setWo_id(prd.getWo_id_fk());
                xpiwipeqOA2.setMdl_id_fk(prd.getMdl_id_fk());
                xpiwipeqOA2.setPrd_qty(prd.getPrd_qty());
                xpiwipeqOA2.setPrd_std_qty(prd.getPrd_std_qty());
                xpiwipeqOA2.setSht_ope_msg(prd.getSht_ope_msg());
                xpiwipeqOA2.setMtrl_box_id_fk(prd.getMtrl_box_id_fk());
                xpiwipeqOA2.setPrd_stat(prd.getPrd_stat());
                xpiwipeqOA2.setPv_prd_grade(prd.getPv_prd_grade());
                xpiwipeqOA2.setGroup_id(prd.getGroup_id());
                if (!Util.isSpaceCheck(gproc_flg)) {
                    xpiwipeqOA2.setProc_flg(gproc_flg);
                }
                //增加返工品标识
                if (!Util.isSpaceCheck(prd.getOqc_skip_flg())) {
                    xpiwipeqOA2.setOqc_skip_flg(prd.getOqc_skip_flg());
                }

                if (PROC_IN_PROCESS.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setBox_id(prd.getBox_id_fk());
                    xpiwipeqOA2.setPv_box_id_fk(prd.getPv_box_id_fk());
                } else if (PROC_WAIT.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setBox_id("");
                    xpiwipeqOA2.setPv_box_id_fk(prd.getBox_id_fk());
                }
                xpiwipeqOA2.setX_axis_cnt_fk(prd.getX_axis_cnt_fk());
                xpiwipeqOA2.setY_axis_cnt_fk(prd.getY_axis_cnt_fk());
                if (null != prd.getT_rubbing_time()) {
                    xpiwipeqOA2.setTft_buff_time(prd.getT_rubbing_time()
                            .toString());
                }
                if (null != prd.getC_rubbing_time()) {
                    xpiwipeqOA2.setCf_buff_time(prd.getC_rubbing_time()
                            .toString());
                }

                if (prd.getP1_timestamp() != null) {
                    xpiwipeqOA2.setStart_time(prd.getP1_timestamp());

                    xpiwipeqOA2.setProcess_user(prd.getEvt_usr());
                    if (prd.getP2_timestamp() != null) {
                        xpiwipeqOA2.setEnd_time(prd.getP2_timestamp());
                    }
                }
                if (prd.getLogon_timestamp() != null) {
                    xpiwipeqOA2.setLogon_usr(prd.getLogon_usr());
                    xpiwipeqOA2.setLogon_timestamp(prd.getLogon_timestamp());
                }
                if (prd.getLogof_timestamp() != null) {
                    xpiwipeqOA2.setLogof_usr(prd.getLogof_usr());
                    xpiwipeqOA2.setLogof_timestamp(prd.getLogof_timestamp());
                }
                oary_prd.add(xpiwipeqOA2);
            }
            outTrx.setOary_prd(oary_prd);
            outTrx.setTbl_cnt(oary_prd.size());
        } else {
            gszMsgBuf = "来料箱号在当前站点[" + bis_ope.getOpe_dsc() + "]未找到WIP信息,请确认！";
            return E_XPIWIPEQ_NO_WIP;
        }

        return lRc;
    }

    /**
     * Get WAIT&INPR prd list
     *
     * @return
     */
    private long getPrdList() {
        long lRc = _NORMAL;

        // Get Pep_lvl
        Bis_ope bis_ope = new Bis_ope();
        Bis_opeId bis_opeId = new Bis_opeId();
        bis_opeId.setOpe_id(inTrx.getCr_ope_id());
        bis_opeId.setOpe_ver(inTrx.getCr_ope_ver());

        bis_ope = bisOpeDao.get(bis_opeId);
        if (null == bis_ope) {
            gszMsgBuf = new NotFoundRtnBeen(bis_opeId.toString(), Bis_ope.class)
                    .toString();
            return E_BIS_OPE + E_READ_NOT_FOUND;
        }

        // Get prd list
        List<Ret_prd_info> ret_prd_infoList = new ArrayList<Ret_prd_info>();

        String sql = "";

        if (!Util.isSpaceCheck(inTrx.getBox_id())) {
            sql = "FROM Ret_prd_info WHERE  prd_stat='INPR' AND cr_ope_id_fk='"
                    + inTrx.getCr_ope_id()
                    + "' AND cr_ope_ver_fk = '"
                    + inTrx.getCr_ope_ver()
                    + "' AND box_id_fk='"
                    + inTrx.getBox_id() + "'";
        } else if (!Util.isSpaceCheck(inTrx.getPv_box_id())) {
            sql = "FROM Ret_prd_info WHERE  ((prd_stat='INPR' AND cr_ope_id_fk='"
                    + inTrx.getCr_ope_id()
                    + "' AND cr_ope_ver_fk = '"
                    + inTrx.getCr_ope_ver()
                    + "' AND pv_box_id_fk='" + inTrx.getPv_box_id()
                    + "') or (prd_stat='WAIT' AND nx_ope_id_fk='"
                    + inTrx.getCr_ope_id()
                    + "' AND nx_ope_ver_fk = '"
                    + inTrx.getCr_ope_ver()
                    + "' AND box_id_fk='" + inTrx.getPv_box_id() + "'))";
        } else {
            sql = "FROM Ret_prd_info WHERE  ((prd_stat='INPR' AND cr_ope_id_fk='"
                    + inTrx.getCr_ope_id()
                    + "' AND cr_ope_ver_fk = '"
                    + inTrx.getCr_ope_ver()
                    + "') or (prd_stat='WAIT' AND nx_ope_id_fk='"
                    + inTrx.getCr_ope_id()
                    + "' AND nx_ope_ver_fk = '"
                    + inTrx.getCr_ope_ver() + "'))";
        }

        if (!Util.isSpaceCheck(inTrx.getWo_id())) {
            sql = sql + " AND wo_id_fk='" + inTrx.getWo_id() + "'";
        }
        if (!Util.isSpaceCheck(inTrx.getLot_id())) {
            sql = sql + " AND lot_id='" + inTrx.getLot_id() + "'";
        }
        if (!Util.isSpaceCheck(inTrx.getPrd_id())) {
            sql = sql + " AND prd_seq_id='" + inTrx.getPrd_id() + "'";
        }
        if (!Util.isSpaceCheck(inTrx.getMtrl_box_id())) {
            sql = sql + " AND mtrl_box_id_fk='" + inTrx.getMtrl_box_id() + "'";
        }

        sql = sql + " ORDER BY box_id_fk,pv_box_id_fk, convert(slot_no,UNSIGNED) ";

        ret_prd_infoList = retPrdInfoDao.find(sql);
        outTrx.setTbl_cnt(0);
        if (!ret_prd_infoList.isEmpty()) {
            List<XpiwipeqOA2> oary_prd = new ArrayList<XpiwipeqOA2>();
            for (Ret_prd_info prd : ret_prd_infoList) {
                XpiwipeqOA2 xpiwipeqOA2 = new XpiwipeqOA2();
                Ret_wo ret_wo = retWoDao.get(prd.getWo_id_fk());
                if (ret_wo == null) {
                    xpiwipeqOA2.setCus_id("");
                } else {
                    xpiwipeqOA2.setCus_id(ret_wo.getCus_id_fk());
                }
                xpiwipeqOA2.setPrd_seq_id(prd.getPrd_seq_id());
                xpiwipeqOA2.setSlot_no(prd.getSlot_no());
                xpiwipeqOA2.setMtrl_slot_no_fk(prd.getMtrl_slot_no_fk());
                xpiwipeqOA2.setEvt_timestamp(prd.getEvt_timestamp().toString());
                xpiwipeqOA2.setEvt_user(prd.getEvt_usr());
                xpiwipeqOA2.setLot_id(prd.getLot_id());
                if (PROC_IN_PROCESS.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setPrd_grade(prd.getPrd_grade());
                } else {
                    xpiwipeqOA2.setPrd_grade(_SPACE);
                }
                String pathId = PROC_WAIT.equals(prd.getPrd_stat()) ? prd.getNx_path_id_fk() : prd.getCr_path_id_fk();
                String pathVer = PROC_WAIT.equals(prd.getPrd_stat()) ? prd.getNx_path_ver_fk() : prd.getCr_path_ver_fk();
                xpiwipeqOA2.setCr_proc(prd.getCr_proc_id_fk());
                xpiwipeqOA2.setCr_ope_id(prd.getCr_ope_id_fk());
                xpiwipeqOA2.setCr_ope_no_fk(prd.getCr_ope_no_fk());
                xpiwipeqOA2.setCr_ope_ver_fk(prd.getCr_ope_ver_fk());
                xpiwipeqOA2.setCr_path_id_fk(prd.getCr_path_id_fk());
                xpiwipeqOA2.setCr_path_ver_fk(prd.getCr_path_ver_fk());
                xpiwipeqOA2.setCr_tool_id_fk(prd.getCr_tool_id_fk());
                xpiwipeqOA2.setFab_sn(prd.getFab_sn());
                xpiwipeqOA2.setPep_lvl(bis_ope.getPep_lvl());
                xpiwipeqOA2.setWo_id(prd.getWo_id_fk());
                xpiwipeqOA2.setMdl_id_fk(prd.getMdl_id_fk());
                xpiwipeqOA2.setPrd_qty(prd.getPrd_qty());
                xpiwipeqOA2.setPrd_std_qty(prd.getPrd_std_qty());
                xpiwipeqOA2.setSht_ope_msg(prd.getSht_ope_msg());
                xpiwipeqOA2.setPrd_stat(prd.getPrd_stat());
                xpiwipeqOA2.setPv_prd_grade(prd.getPv_prd_grade());
                xpiwipeqOA2.setDs_recipe_id(prd.getDs_recipe_id());
                xpiwipeqOA2.setGroup_id(prd.getGroup_id());
                //增加 下站制程代码属性
                xpiwipeqOA2.setNx_proc_id_fk(prd.getNx_proc_id_fk());
                if (!Util.isSpaceCheck(gproc_flg)) {
                    xpiwipeqOA2.setProc_flg(gproc_flg);
                }
                //增加返工品标识
                Bis_pathiId id = new Bis_pathiId();
                id.setPath_id(pathId);
                id.setPath_ver(pathVer);
                Bis_pathi bis_pathi = bisPathiDao.get(id);
                if (bis_pathi != null) {
                    if (bis_pathi.getPath_cate().equals(PATH_TYPE_REWK)) {
                        xpiwipeqOA2.setOqc_skip_flg(_YES);
                    } else {
                        xpiwipeqOA2.setOqc_skip_flg(_NO);
                    }
                }

                xpiwipeqOA2.setPrd_admin_flg(prd.getPrd_admin_flg());
                if (null != prd.getPrd_admin_flg()) {
                    StringBuffer prd_admin_flg_sb = new StringBuffer(prd.getPrd_admin_flg());
                    String ipqc_flg = "OK";
                    String th_judge_flg = "OK";
                    String fz_flg = "OK";
                    if (prd_admin_flg_sb.charAt(1) == 'Y') {
                        ipqc_flg = "NG";
                    } else if (prd_admin_flg_sb.charAt(1) == 'N') {
                        ipqc_flg = "OK";
                    } else if (prd_admin_flg_sb.charAt(1) == 'S') {
                        ipqc_flg = "SC";
                    } else {
                        ipqc_flg = "";
                    }
                    if (prd_admin_flg_sb.charAt(2) == 'Y') {
                        th_judge_flg = "NG";
                    } else if (prd_admin_flg_sb.charAt(2) == 'N') {
                        th_judge_flg = "OK";
                    } else {
                        th_judge_flg = "";
                    }
                    if (prd_admin_flg_sb.charAt(3) == 'Y') {
                        fz_flg = "NG";
                    } else if (prd_admin_flg_sb.charAt(3) == 'N') {
                        fz_flg = "OK";
                    } else {
                        fz_flg = "";
                    }
                    xpiwipeqOA2.setIpqc_flg(ipqc_flg);
                    xpiwipeqOA2.setTh_judge_flg(th_judge_flg);
                    xpiwipeqOA2.setFz_flg(fz_flg);
                } else {
                    xpiwipeqOA2.setIpqc_flg("");
                    xpiwipeqOA2.setTh_judge_flg("");
                    xpiwipeqOA2.setFz_flg("");
                }

                if (PROC_IN_PROCESS.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setBox_id(prd.getBox_id_fk());
                    xpiwipeqOA2.setPv_box_id_fk(prd.getPv_box_id_fk());
                } else if (PROC_WAIT.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setBox_id("");
                    xpiwipeqOA2.setPv_box_id_fk(prd.getBox_id_fk());
                }
                xpiwipeqOA2.setMtrl_box_id_fk(prd.getMtrl_box_id_fk());
                xpiwipeqOA2.setX_axis_cnt_fk(prd.getX_axis_cnt_fk());
                xpiwipeqOA2.setY_axis_cnt_fk(prd.getY_axis_cnt_fk());
                if (null != prd.getT_rubbing_time()) {
                    xpiwipeqOA2.setTft_buff_time(prd.getT_rubbing_time()
                            .toString());
                }
                if (null != prd.getC_rubbing_time()) {
                    xpiwipeqOA2.setCf_buff_time(prd.getC_rubbing_time()
                            .toString());
                }

                if (prd.getP1_timestamp() != null && PROC_IN_PROCESS.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setStart_time(prd.getP1_timestamp());
                    xpiwipeqOA2.setProcess_user(prd.getEvt_usr());
                    if (prd.getP2_timestamp() != null) {
                        xpiwipeqOA2.setEnd_user(prd.getEvt_usr());
                        xpiwipeqOA2.setEnd_time(prd.getP2_timestamp());
                    }
                }
                if (prd.getLogon_timestamp() != null && PROC_IN_PROCESS.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setLogon_usr(prd.getLogon_usr());
                    xpiwipeqOA2.setLogon_timestamp(prd.getLogon_timestamp());
                }
                if (prd.getLogof_timestamp() != null) {
                    xpiwipeqOA2.setLogof_usr(prd.getLogof_usr());
                    xpiwipeqOA2.setLogof_timestamp(prd.getLogof_timestamp());
                }

                oary_prd.add(xpiwipeqOA2);
            }
            outTrx.setOary_prd(oary_prd);
            outTrx.setTbl_cnt(oary_prd.size());
        }

        return lRc;
    }

    private long getPrdWipWaitJBList() {
        long lRc = _NORMAL;

        // Get Pep_lvl
        Bis_ope bis_ope = new Bis_ope();
        Bis_opeId bis_opeId = new Bis_opeId();
        bis_opeId.setOpe_id(inTrx.getCr_ope_id());
        bis_opeId.setOpe_ver(inTrx.getCr_ope_ver());

        bis_ope = bisOpeDao.get(bis_opeId);
        if (null == bis_ope) {
            gszMsgBuf = new NotFoundRtnBeen(bis_opeId.toString(), Bis_ope.class)
                    .toString();
            return E_BIS_OPE + E_READ_NOT_FOUND;
        }

        // Get prd list
        List<Ret_prd_info> ret_prd_infoList = new ArrayList<Ret_prd_info>();

        String sql = "SELECT a.mtrl_box_id_fk, COUNT(a.prd_seq_id) ,b.prd_proc_qty FROM RET_PRD_INFO a " +
                "LEFT JOIN RET_PRD_IN b ON a.mtrl_box_id_fk = b.mtrl_box_id " +
                "WHERE a.cr_ope_id_fk = '" +
                inTrx.getCr_ope_id() + "'" +
                "AND a.cr_ope_ver_fk = '" +
                inTrx.getCr_ope_ver() + "'" +
                "AND a.prd_stat = 'INPR'";

        String hql = "FROM Ret_prd_info where prd_stat = 'WAIT' " +
                "AND nx_ope_id_fk = '" +
                inTrx.getCr_ope_id() + "'" +
                "AND nx_ope_ver_fk = '" +
                inTrx.getCr_ope_ver() + "'";

        if (!Util.isSpaceCheck(inTrx.getBox_id())) {
            sql = sql + " AND a.box_id_fk='" + inTrx.getBox_id() + "'";
            hql = hql + " AND box_id_fk='" + inTrx.getBox_id() + "'";
        } else if (!Util.isSpaceCheck(inTrx.getPv_box_id())) {
            sql = sql + " AND a.pv_box_id_fk='" + inTrx.getPv_box_id() + "'";
            hql = hql + " AND box_id_fk='" + inTrx.getPv_box_id() + "'";
        }
        if (!Util.isSpaceCheck(inTrx.getWo_id())) {
            sql = sql + " AND a.wo_id_fk='" + inTrx.getWo_id() + "'";
            hql += "AND wo_id_fk = '" + inTrx.getWo_id() + "'";
        }
        if (!Util.isSpaceCheck(inTrx.getLot_id())) {
            sql = sql + " AND a.lot_id='" + inTrx.getLot_id() + "'";
            hql += "AND lot_id = '" + inTrx.getLot_id() + "'";
        }
        if (!Util.isSpaceCheck(inTrx.getPrd_id())) {
            sql = sql + " AND a.prd_seq_id='" + inTrx.getPrd_id() + "'";
            hql += "AND prd_seq_id = '" + inTrx.getPrd_id() + "'";
        }
        if (!Util.isSpaceCheck(inTrx.getMtrl_box_id())) {
            sql = sql + " AND a.mtrl_box_id_fk='" + inTrx.getMtrl_box_id() + "'";
            hql += "AND mtrl_box_id_fk = '" + inTrx.getMtrl_box_id() + "'";
        }
        if (!Util.isSpaceCheck(inTrx.getLot_id())) {
            hql += "AND lot_id = '" + inTrx.getLot_id() + "'";
        }

        sql = sql + " group by a.mtrl_box_id_fk";
        hql += " order by box_id_fk,convert(slot_no,UNSIGNED)";

        List<Object> list = retPrdInfoDao.findBySQL(sql);
        outTrx.setTbl_cnt(0);
        List<Ret_prd_info> ret_prd_info_list1 = new ArrayList<Ret_prd_info>();
        List<XpiwipeqOA2> oary_prd = new ArrayList<XpiwipeqOA2>();
        if (!list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                Object[] obj = (Object[]) list.get(i);
                Ret_prd_info ret_prd_info = new Ret_prd_info();
                if ((_YES).equals(inTrx.getCheck_flg())) {
                    if (obj[2] == null) {
                        continue;
                    }
                    if (Integer.parseInt(obj[1].toString()) != Integer.parseInt(obj[2].toString())) {
                        ret_prd_info.setMtrl_box_id_fk(obj[0].toString());
                        ret_prd_info_list1.add(ret_prd_info);
                    }
                } else {
                    if (obj[2] == null) {
                        continue;
                    }
                    if (Integer.parseInt(obj[1].toString()) == Integer.parseInt(obj[2].toString())) {
                        ret_prd_info.setMtrl_box_id_fk(obj[0].toString());
                        ret_prd_info_list1.add(ret_prd_info);
                    }
                }

            }
            String sql1 = "FROM Ret_prd_info where ( 1=0 ";
            for (Ret_prd_info prd : ret_prd_info_list1) {
                sql1 = sql1 + "OR mtrl_box_id_fk = '" + prd.getMtrl_box_id_fk() + "'";
            }
            sql1 += ")";
            if (!Util.isSpaceCheck(inTrx.getBox_id())) {
                sql1 += "AND box_id_fk = '" + inTrx.getBox_id() + "'";
            }
            if (!Util.isSpaceCheck(inTrx.getLot_id())) {
                sql1 += "AND lot_id = '" + inTrx.getLot_id() + "'";
            }
            if (!Util.isSpaceCheck(inTrx.getPv_box_id())) {
                sql1 += "AND pv_box_id_fk = '" + inTrx.getPv_box_id() + "'";
            }
            sql1 = sql1 +
                    "AND cr_ope_id_fk = '" +
                    inTrx.getCr_ope_id() + "'" +
                    "AND cr_ope_ver_fk = '" +
                    inTrx.getCr_ope_ver() + "'" +
                    "AND prd_stat = 'INPR'" +
                    "order by pv_box_id_fk,convert(slot_no,UNSIGNED)";

            List<Ret_prd_info> ret_prd_info_list = new ArrayList<Ret_prd_info>();
            ret_prd_info_list = retPrdInfoDao.find(sql1);

            for (Ret_prd_info prd : ret_prd_info_list) {
                XpiwipeqOA2 xpiwipeqOA2 = new XpiwipeqOA2();
                Ret_wo ret_wo = retWoDao.get(prd.getWo_id_fk());
                if (ret_wo == null) {
                    xpiwipeqOA2.setCus_id("");
                } else {
                    xpiwipeqOA2.setCus_id(ret_wo.getCus_id_fk());
                }
                xpiwipeqOA2.setPrd_seq_id(prd.getPrd_seq_id());
                xpiwipeqOA2.setSlot_no(prd.getSlot_no());
                xpiwipeqOA2.setMtrl_slot_no_fk(prd.getMtrl_slot_no_fk());
                xpiwipeqOA2.setEvt_timestamp(prd.getEvt_timestamp().toString());
                xpiwipeqOA2.setEvt_user(prd.getEvt_usr());
                xpiwipeqOA2.setLot_id(prd.getLot_id());
                if (PROC_IN_PROCESS.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setPrd_grade(prd.getPrd_grade());
                } else {
                    xpiwipeqOA2.setPrd_grade(_SPACE);
                }
                xpiwipeqOA2.setCr_proc(prd.getCr_proc_id_fk());
                xpiwipeqOA2.setCr_ope_id(prd.getCr_ope_id_fk());
                xpiwipeqOA2.setCr_ope_no_fk(prd.getCr_ope_no_fk());
                xpiwipeqOA2.setCr_ope_ver_fk(prd.getCr_ope_ver_fk());
                xpiwipeqOA2.setCr_path_id_fk(prd.getCr_path_id_fk());
                xpiwipeqOA2.setCr_path_ver_fk(prd.getCr_path_ver_fk());
                xpiwipeqOA2.setCr_tool_id_fk(prd.getCr_tool_id_fk());
                xpiwipeqOA2.setFab_sn(prd.getFab_sn());
                xpiwipeqOA2.setPep_lvl(bis_ope.getPep_lvl());
                xpiwipeqOA2.setWo_id(prd.getWo_id_fk());
                xpiwipeqOA2.setMdl_id_fk(prd.getMdl_id_fk());
                xpiwipeqOA2.setPrd_qty(prd.getPrd_qty());
                xpiwipeqOA2.setPrd_std_qty(prd.getPrd_std_qty());
                xpiwipeqOA2.setSht_ope_msg(prd.getSht_ope_msg());
                xpiwipeqOA2.setPrd_stat(prd.getPrd_stat());
                xpiwipeqOA2.setPv_prd_grade(prd.getPv_prd_grade());
                xpiwipeqOA2.setDs_recipe_id(prd.getDs_recipe_id());
                xpiwipeqOA2.setPrd_admin_flg(prd.getPrd_admin_flg());
                xpiwipeqOA2.setGroup_id(prd.getGroup_id());
                if (!Util.isSpaceCheck(gproc_flg)) {
                    xpiwipeqOA2.setProc_flg(gproc_flg);
                }
                //增加返工品标识
                if (!Util.isSpaceCheck(prd.getOqc_skip_flg())) {
                    xpiwipeqOA2.setOqc_skip_flg(prd.getOqc_skip_flg());
                }

                if (null != prd.getPrd_admin_flg()) {
                    StringBuffer prd_admin_flg_sb = new StringBuffer(prd.getPrd_admin_flg());
                    String ipqc_flg = "OK";
                    String th_judge_flg = "OK";
                    String fz_flg = "OK";
                    if (prd_admin_flg_sb.charAt(1) == 'Y') {
                        ipqc_flg = "NG";
                    } else if (prd_admin_flg_sb.charAt(1) == 'N') {
                        ipqc_flg = "OK";
                    } else if (prd_admin_flg_sb.charAt(1) == 'S') {
                        ipqc_flg = "SC";
                    } else {
                        ipqc_flg = "";
                    }
                    if (prd_admin_flg_sb.charAt(2) == 'Y') {
                        th_judge_flg = "NG";
                    } else if (prd_admin_flg_sb.charAt(2) == 'N') {
                        th_judge_flg = "OK";
                    } else {
                        th_judge_flg = "";
                    }
                    if (prd_admin_flg_sb.charAt(3) == 'Y') {
                        fz_flg = "NG";
                    } else if (prd_admin_flg_sb.charAt(3) == 'N') {
                        fz_flg = "OK";
                    } else {
                        fz_flg = "";
                    }
                    xpiwipeqOA2.setIpqc_flg(ipqc_flg);
                    xpiwipeqOA2.setTh_judge_flg(th_judge_flg);
                    xpiwipeqOA2.setFz_flg(fz_flg);
                } else {
                    xpiwipeqOA2.setIpqc_flg("");
                    xpiwipeqOA2.setTh_judge_flg("");
                    xpiwipeqOA2.setFz_flg("");
                }

                if (PROC_IN_PROCESS.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setBox_id(prd.getBox_id_fk());
                    xpiwipeqOA2.setPv_box_id_fk(prd.getPv_box_id_fk());
                } else if (PROC_WAIT.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setBox_id("");
                    xpiwipeqOA2.setPv_box_id_fk(prd.getBox_id_fk());
                }
                xpiwipeqOA2.setMtrl_box_id_fk(prd.getMtrl_box_id_fk());
                xpiwipeqOA2.setX_axis_cnt_fk(prd.getX_axis_cnt_fk());
                xpiwipeqOA2.setY_axis_cnt_fk(prd.getY_axis_cnt_fk());
                if (null != prd.getT_rubbing_time()) {
                    xpiwipeqOA2.setTft_buff_time(prd.getT_rubbing_time()
                            .toString());
                }
                if (null != prd.getC_rubbing_time()) {
                    xpiwipeqOA2.setCf_buff_time(prd.getC_rubbing_time()
                            .toString());
                }

                if (prd.getP1_timestamp() != null && PROC_IN_PROCESS.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setStart_time(prd.getP1_timestamp());
                    xpiwipeqOA2.setProcess_user(prd.getEvt_usr());
                    if (prd.getP2_timestamp() != null) {
                        xpiwipeqOA2.setEnd_user(prd.getEvt_usr());
                        xpiwipeqOA2.setEnd_time(prd.getP2_timestamp());
                    }
                }
                if (prd.getLogon_timestamp() != null && PROC_IN_PROCESS.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setLogon_usr(prd.getLogon_usr());
                    xpiwipeqOA2.setLogon_timestamp(prd.getLogon_timestamp());
                }
                if (prd.getLogof_timestamp() != null) {
                    xpiwipeqOA2.setLogof_usr(prd.getLogof_usr());
                    xpiwipeqOA2.setLogof_timestamp(prd.getLogof_timestamp());
                }

                oary_prd.add(xpiwipeqOA2);
            }
        }

        if ((_NO).equals(inTrx.getCheck_flg())) {
            List<Ret_prd_info> ret_prd_info_wait_list = new ArrayList<Ret_prd_info>();
            ret_prd_info_wait_list = retPrdInfoDao.find(hql);
            for (Ret_prd_info prd : ret_prd_info_wait_list) {
                XpiwipeqOA2 xpiwipeqOA2 = new XpiwipeqOA2();
                xpiwipeqOA2.setPrd_seq_id(prd.getPrd_seq_id());
                xpiwipeqOA2.setSlot_no(prd.getSlot_no());
                xpiwipeqOA2.setMtrl_slot_no_fk(prd.getMtrl_slot_no_fk());
                xpiwipeqOA2.setEvt_timestamp(prd.getEvt_timestamp().toString());
                xpiwipeqOA2.setEvt_user(prd.getEvt_usr());
                xpiwipeqOA2.setLot_id(prd.getLot_id());
                if (PROC_IN_PROCESS.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setPrd_grade(prd.getPrd_grade());
                } else {
                    xpiwipeqOA2.setPrd_grade(_SPACE);
                }
                xpiwipeqOA2.setCr_proc(prd.getCr_proc_id_fk());
                xpiwipeqOA2.setCr_ope_id(prd.getCr_ope_id_fk());
                xpiwipeqOA2.setCr_ope_no_fk(prd.getCr_ope_no_fk());
                xpiwipeqOA2.setCr_ope_ver_fk(prd.getCr_ope_ver_fk());
                xpiwipeqOA2.setCr_path_id_fk(prd.getCr_path_id_fk());
                xpiwipeqOA2.setCr_path_ver_fk(prd.getCr_path_ver_fk());
                xpiwipeqOA2.setCr_tool_id_fk(prd.getCr_tool_id_fk());
                xpiwipeqOA2.setFab_sn(prd.getFab_sn());
                xpiwipeqOA2.setPep_lvl(bis_ope.getPep_lvl());
                xpiwipeqOA2.setWo_id(prd.getWo_id_fk());
                xpiwipeqOA2.setMdl_id_fk(prd.getMdl_id_fk());
                xpiwipeqOA2.setPrd_qty(prd.getPrd_qty());
                xpiwipeqOA2.setPrd_std_qty(prd.getPrd_std_qty());
                xpiwipeqOA2.setSht_ope_msg(prd.getSht_ope_msg());
                xpiwipeqOA2.setPrd_stat(prd.getPrd_stat());
                xpiwipeqOA2.setPv_prd_grade(prd.getPv_prd_grade());
                xpiwipeqOA2.setPrd_admin_flg(prd.getPrd_admin_flg());
                xpiwipeqOA2.setGroup_id(prd.getGroup_id());
                if (!Util.isSpaceCheck(gproc_flg)) {
                    xpiwipeqOA2.setProc_flg(gproc_flg);
                }
                //增加返工品标识
                if (!Util.isSpaceCheck(prd.getOqc_skip_flg())) {
                    xpiwipeqOA2.setOqc_skip_flg(prd.getOqc_skip_flg());
                }

                if (null != prd.getPrd_admin_flg()) {
                    StringBuffer prd_admin_flg_sb = new StringBuffer(prd.getPrd_admin_flg());
                    String ipqc_flg = "OK";
                    String th_judge_flg = "OK";
                    String fz_flg = "OK";
                    if (prd_admin_flg_sb.charAt(1) == 'Y') {
                        ipqc_flg = "NG";
                    } else if (prd_admin_flg_sb.charAt(1) == 'N') {
                        ipqc_flg = "OK";
                    } else if (prd_admin_flg_sb.charAt(1) == 'S') {
                        ipqc_flg = "SC";
                    } else {
                        ipqc_flg = "";
                    }
                    if (prd_admin_flg_sb.charAt(2) == 'Y') {
                        th_judge_flg = "NG";
                    } else if (prd_admin_flg_sb.charAt(2) == 'N') {
                        th_judge_flg = "OK";
                    } else {
                        th_judge_flg = "";
                    }
                    if (prd_admin_flg_sb.charAt(3) == 'Y') {
                        fz_flg = "NG";
                    } else if (prd_admin_flg_sb.charAt(3) == 'N') {
                        fz_flg = "OK";
                    } else {
                        fz_flg = "";
                    }
                    xpiwipeqOA2.setIpqc_flg(ipqc_flg);
                    xpiwipeqOA2.setTh_judge_flg(th_judge_flg);
                    xpiwipeqOA2.setFz_flg(fz_flg);
                } else {
                    xpiwipeqOA2.setIpqc_flg("");
                    xpiwipeqOA2.setTh_judge_flg("");
                    xpiwipeqOA2.setFz_flg("");
                }

                if (PROC_IN_PROCESS.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setBox_id(prd.getBox_id_fk());
                    xpiwipeqOA2.setPv_box_id_fk(prd.getPv_box_id_fk());
                } else if (PROC_WAIT.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setBox_id("");
                    xpiwipeqOA2.setPv_box_id_fk(prd.getBox_id_fk());
                }
                xpiwipeqOA2.setMtrl_box_id_fk(prd.getMtrl_box_id_fk());
                xpiwipeqOA2.setX_axis_cnt_fk(prd.getX_axis_cnt_fk());
                xpiwipeqOA2.setY_axis_cnt_fk(prd.getY_axis_cnt_fk());
                if (null != prd.getT_rubbing_time()) {
                    xpiwipeqOA2.setTft_buff_time(prd.getT_rubbing_time()
                            .toString());
                }
                if (null != prd.getC_rubbing_time()) {
                    xpiwipeqOA2.setCf_buff_time(prd.getC_rubbing_time()
                            .toString());
                }

                if (prd.getP1_timestamp() != null && PROC_IN_PROCESS.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setStart_time(prd.getP1_timestamp());
                    xpiwipeqOA2.setProcess_user(prd.getEvt_usr());
                    if (prd.getP2_timestamp() != null) {
                        xpiwipeqOA2.setEnd_user(prd.getEvt_usr());
                        xpiwipeqOA2.setEnd_time(prd.getP2_timestamp());
                    }
                }
                if (prd.getLogon_timestamp() != null && PROC_IN_PROCESS.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setLogon_usr(prd.getLogon_usr());
                    xpiwipeqOA2.setLogon_timestamp(prd.getLogon_timestamp());
                }
                if (prd.getLogof_timestamp() != null) {
                    xpiwipeqOA2.setLogof_usr(prd.getLogof_usr());
                    xpiwipeqOA2.setLogof_timestamp(prd.getLogof_timestamp());
                }
                oary_prd.add(xpiwipeqOA2);
            }
        }

        outTrx.setOary_prd(oary_prd);
        outTrx.setTbl_cnt(oary_prd.size());

        return lRc;
    }

    private long getPrdWipWaitDMList() {
        long lRc = _NORMAL;

        // Get Pep_lvl
        Bis_ope bis_ope = new Bis_ope();
        Bis_opeId bis_opeId = new Bis_opeId();
        bis_opeId.setOpe_id(inTrx.getCr_ope_id());
        bis_opeId.setOpe_ver(inTrx.getCr_ope_ver());

        bis_ope = bisOpeDao.get(bis_opeId);
        if (null == bis_ope) {
            gszMsgBuf = new NotFoundRtnBeen(bis_opeId.toString(), Bis_ope.class)
                    .toString();
            return E_BIS_OPE + E_READ_NOT_FOUND;
        }

        String sql = "SELECT a.LOT_ID,COUNT(a.prd_seq_id) ,b.LOT_QTY FROM RET_PRD_INFO a " +
                "LEFT JOIN RET_PRD_LOT b ON a.LOT_ID = b.LOT_ID " +
                "WHERE a.cr_ope_id_fk = '" +
                inTrx.getCr_ope_id() + "'" +
                "AND a.cr_ope_ver_fk = '" +
                inTrx.getCr_ope_ver() + "'" +
                "AND a.prd_stat = 'INPR'";

        String hql = "FROM Ret_prd_info where prd_stat = 'WAIT' " +
                "AND nx_ope_id_fk = '" +
                inTrx.getCr_ope_id() + "'" +
                "AND nx_ope_ver_fk = '" +
                inTrx.getCr_ope_ver() + "'";

        if (!Util.isSpaceCheck(inTrx.getBox_id())) {
            sql = sql + " AND a.box_id_fk='" + inTrx.getBox_id() + "'";
            hql = hql + " AND box_id_fk='" + inTrx.getBox_id() + "'";
        } else if (!Util.isSpaceCheck(inTrx.getPv_box_id())) {
            sql = sql + " AND a.pv_box_id_fk='" + inTrx.getPv_box_id() + "'";
            hql = hql + " AND box_id_fk='" + inTrx.getPv_box_id() + "'";
        }

        if (!Util.isSpaceCheck(inTrx.getWo_id())) {
            sql = sql + " AND a.wo_id_fk='" + inTrx.getWo_id() + "'";
            hql += "AND wo_id_fk = '" + inTrx.getWo_id() + "'";
        }
        if (!Util.isSpaceCheck(inTrx.getLot_id())) {
            sql = sql + " AND a.lot_id='" + inTrx.getLot_id() + "'";
            hql += "AND lot_id = '" + inTrx.getLot_id() + "'";
        }
        if (!Util.isSpaceCheck(inTrx.getPrd_id())) {
            sql = sql + " AND a.prd_seq_id='" + inTrx.getPrd_id() + "'";
            hql += "AND prd_seq_id = '" + inTrx.getPrd_id() + "'";
        }
        if (!Util.isSpaceCheck(inTrx.getMtrl_box_id())) {
            sql = sql + " AND a.mtrl_box_id_fk='" + inTrx.getMtrl_box_id() + "'";
            hql += "AND mtrl_box_id_fk = '" + inTrx.getMtrl_box_id() + "'";
        }
        if (!Util.isSpaceCheck(inTrx.getLot_id())) {
            hql += "AND lot_id = '" + inTrx.getLot_id() + "'";
        }

        sql = sql + "GROUP BY a.LOT_ID ";
        hql += " order by box_id_fk, convert(slot_no,UNSIGNED)";

        List<Object> list = retPrdInfoDao.findBySQL(sql);
        outTrx.setTbl_cnt(0);
        List<Ret_prd_info> ret_prd_info_list1 = new ArrayList<Ret_prd_info>();
        List<XpiwipeqOA2> oary_prd = new ArrayList<XpiwipeqOA2>();

        if (!list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                Object[] obj = (Object[]) list.get(i);

                Ret_prd_info ret_prd_info = new Ret_prd_info();
                if ((_YES).equals(inTrx.getCheck_flg())) {
                    if (obj[2] == null) {
                        continue;
                    }
                    if (Integer.parseInt(obj[1].toString()) != Integer.parseInt(obj[2].toString())) {
                        ret_prd_info.setLot_id(obj[0].toString());
                        ret_prd_info_list1.add(ret_prd_info);
                    }
                } else {
                    if (obj[2] == null) {
                        continue;
                    }
                    if (Integer.parseInt(obj[1].toString()) == Integer.parseInt(obj[2].toString())) {
                        ret_prd_info.setLot_id(obj[0].toString());
                        ret_prd_info_list1.add(ret_prd_info);
                    }
                }

            }

            /**
             * 这里的1=0没有问题
             * 解释:如果lot_id为空,那么不显示结果,所以加上1=0
             */
            String sql1 = "FROM Ret_prd_info where  ( 1=0";
            for (Ret_prd_info prd : ret_prd_info_list1) {
                sql1 = sql1 + " OR lot_id = '" + prd.getLot_id() + "'";
            }
            sql1 += ")";
            if (!Util.isSpaceCheck(inTrx.getBox_id())) {
                sql1 += "AND box_id_fk = '" + inTrx.getBox_id() + "'";
            }
            if (!Util.isSpaceCheck(inTrx.getLot_id())) {
                sql1 += "AND lot_id = '" + inTrx.getLot_id() + "'";
            }
            if (!Util.isSpaceCheck(inTrx.getPv_box_id())) {
                sql1 += "AND pv_box_id_fk = '" + inTrx.getPv_box_id() + "'";
            }
            if (!Util.isSpaceCheck(inTrx.getMtrl_box_id())) {
                sql1 += "AND mtrl_box_id_fk = '" + inTrx.getMtrl_box_id() + "'";
            }
            sql1 = sql1 +
                    "AND cr_ope_id_fk = '" +
                    inTrx.getCr_ope_id() + "'" +
                    "AND cr_ope_ver_fk = '" +
                    inTrx.getCr_ope_ver() + "'" +
                    "AND prd_stat = 'INPR'" +
                    "order by pv_box_id_fk,convert(slot_no,UNSIGNED)";

            List<Ret_prd_info> ret_prd_info_list = new ArrayList<Ret_prd_info>();
            ret_prd_info_list = retPrdInfoDao.find(sql1);

            for (Ret_prd_info prd : ret_prd_info_list) {
                XpiwipeqOA2 xpiwipeqOA2 = new XpiwipeqOA2();
                Ret_wo ret_wo = retWoDao.get(prd.getWo_id_fk());
                if (ret_wo == null) {
                    xpiwipeqOA2.setCus_id("");
                } else {
                    xpiwipeqOA2.setCus_id(ret_wo.getCus_id_fk());
                }
                xpiwipeqOA2.setPrd_seq_id(prd.getPrd_seq_id());
                xpiwipeqOA2.setSlot_no(prd.getSlot_no());
                xpiwipeqOA2.setMtrl_slot_no_fk(prd.getMtrl_slot_no_fk());
                xpiwipeqOA2.setEvt_timestamp(prd.getEvt_timestamp().toString());
                xpiwipeqOA2.setEvt_user(prd.getEvt_usr());
                xpiwipeqOA2.setLot_id(prd.getLot_id());
                if (PROC_IN_PROCESS.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setPrd_grade(prd.getPrd_grade());
                } else {
                    xpiwipeqOA2.setPrd_grade(_SPACE);
                }
                xpiwipeqOA2.setCr_proc(prd.getCr_proc_id_fk());
                xpiwipeqOA2.setCr_ope_id(prd.getCr_ope_id_fk());
                xpiwipeqOA2.setCr_ope_no_fk(prd.getCr_ope_no_fk());
                xpiwipeqOA2.setCr_ope_ver_fk(prd.getCr_ope_ver_fk());
                xpiwipeqOA2.setCr_path_id_fk(prd.getCr_path_id_fk());
                xpiwipeqOA2.setCr_path_ver_fk(prd.getCr_path_ver_fk());
                xpiwipeqOA2.setCr_tool_id_fk(prd.getCr_tool_id_fk());
                xpiwipeqOA2.setFab_sn(prd.getFab_sn());
                xpiwipeqOA2.setPep_lvl(bis_ope.getPep_lvl());
                xpiwipeqOA2.setWo_id(prd.getWo_id_fk());
                xpiwipeqOA2.setMdl_id_fk(prd.getMdl_id_fk());
                xpiwipeqOA2.setPrd_qty(prd.getPrd_qty());
                xpiwipeqOA2.setPrd_std_qty(prd.getPrd_std_qty());
                xpiwipeqOA2.setSht_ope_msg(prd.getSht_ope_msg());
                xpiwipeqOA2.setPrd_stat(prd.getPrd_stat());
                xpiwipeqOA2.setPv_prd_grade(prd.getPv_prd_grade());
                xpiwipeqOA2.setDs_recipe_id(prd.getDs_recipe_id());
                xpiwipeqOA2.setPrd_admin_flg(prd.getPrd_admin_flg());
                xpiwipeqOA2.setGroup_id(prd.getGroup_id());
                if (!Util.isSpaceCheck(gproc_flg)) {
                    xpiwipeqOA2.setProc_flg(gproc_flg);
                }
                //增加返工品标识
                if (!Util.isSpaceCheck(prd.getOqc_skip_flg())) {
                    xpiwipeqOA2.setOqc_skip_flg(prd.getOqc_skip_flg());
                }

                if (null != prd.getPrd_admin_flg()) {
                    StringBuffer prd_admin_flg_sb = new StringBuffer(prd.getPrd_admin_flg());
                    String ipqc_flg = "OK";
                    String th_judge_flg = "OK";
                    String fz_flg = "OK";
                    if (prd_admin_flg_sb.charAt(1) == 'Y') {
                        ipqc_flg = "NG";
                    } else if (prd_admin_flg_sb.charAt(1) == 'N') {
                        ipqc_flg = "OK";
                    } else if (prd_admin_flg_sb.charAt(1) == 'S') {
                        ipqc_flg = "SC";
                    } else {
                        ipqc_flg = "";
                    }
                    if (prd_admin_flg_sb.charAt(2) == 'Y') {
                        th_judge_flg = "NG";
                    } else if (prd_admin_flg_sb.charAt(2) == 'N') {
                        th_judge_flg = "OK";
                    } else {
                        th_judge_flg = "";
                    }
                    if (prd_admin_flg_sb.charAt(3) == 'Y') {
                        fz_flg = "NG";
                    } else if (prd_admin_flg_sb.charAt(3) == 'N') {
                        fz_flg = "OK";
                    } else {
                        fz_flg = "";
                    }
                    xpiwipeqOA2.setIpqc_flg(ipqc_flg);
                    xpiwipeqOA2.setTh_judge_flg(th_judge_flg);
                    xpiwipeqOA2.setFz_flg(fz_flg);
                } else {
                    xpiwipeqOA2.setIpqc_flg("");
                    xpiwipeqOA2.setTh_judge_flg("");
                    xpiwipeqOA2.setFz_flg("");
                }

                if (PROC_IN_PROCESS.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setBox_id(prd.getBox_id_fk());
                    xpiwipeqOA2.setPv_box_id_fk(prd.getPv_box_id_fk());
                } else if (PROC_WAIT.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setBox_id("");
                    xpiwipeqOA2.setPv_box_id_fk(prd.getBox_id_fk());
                }
                xpiwipeqOA2.setMtrl_box_id_fk(prd.getMtrl_box_id_fk());
                xpiwipeqOA2.setX_axis_cnt_fk(prd.getX_axis_cnt_fk());
                xpiwipeqOA2.setY_axis_cnt_fk(prd.getY_axis_cnt_fk());
                if (null != prd.getT_rubbing_time()) {
                    xpiwipeqOA2.setTft_buff_time(prd.getT_rubbing_time()
                            .toString());
                }
                if (null != prd.getC_rubbing_time()) {
                    xpiwipeqOA2.setCf_buff_time(prd.getC_rubbing_time()
                            .toString());
                }

                if (prd.getP1_timestamp() != null && PROC_IN_PROCESS.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setStart_time(prd.getP1_timestamp());
                    xpiwipeqOA2.setProcess_user(prd.getEvt_usr());
                    if (prd.getP2_timestamp() != null) {
                        xpiwipeqOA2.setEnd_user(prd.getEvt_usr());
                        xpiwipeqOA2.setEnd_time(prd.getP2_timestamp());
                    }
                }
                if (prd.getLogon_timestamp() != null && PROC_IN_PROCESS.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setLogon_usr(prd.getLogon_usr());
                    xpiwipeqOA2.setLogon_timestamp(prd.getLogon_timestamp());
                }
                if (prd.getLogof_timestamp() != null) {
                    xpiwipeqOA2.setLogof_usr(prd.getLogof_usr());
                    xpiwipeqOA2.setLogof_timestamp(prd.getLogof_timestamp());
                }

                oary_prd.add(xpiwipeqOA2);
            }
        }

        if ((_NO).equals(inTrx.getCheck_flg())) {
            List<Ret_prd_info> ret_prd_info_wait_list = new ArrayList<Ret_prd_info>();
            ret_prd_info_wait_list = retPrdInfoDao.find(hql);
            for (Ret_prd_info prd : ret_prd_info_wait_list) {
                XpiwipeqOA2 xpiwipeqOA2 = new XpiwipeqOA2();
                xpiwipeqOA2.setPrd_seq_id(prd.getPrd_seq_id());
                xpiwipeqOA2.setSlot_no(prd.getSlot_no());
                xpiwipeqOA2.setMtrl_slot_no_fk(prd.getMtrl_slot_no_fk());
                xpiwipeqOA2.setEvt_timestamp(prd.getEvt_timestamp().toString());
                xpiwipeqOA2.setEvt_user(prd.getEvt_usr());
                xpiwipeqOA2.setLot_id(prd.getLot_id());
                if (PROC_IN_PROCESS.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setPrd_grade(prd.getPrd_grade());
                } else {
                    xpiwipeqOA2.setPrd_grade(_SPACE);
                }
                xpiwipeqOA2.setCr_proc(prd.getCr_proc_id_fk());
                xpiwipeqOA2.setCr_ope_id(prd.getCr_ope_id_fk());
                xpiwipeqOA2.setCr_ope_no_fk(prd.getCr_ope_no_fk());
                xpiwipeqOA2.setCr_ope_ver_fk(prd.getCr_ope_ver_fk());
                xpiwipeqOA2.setCr_path_id_fk(prd.getCr_path_id_fk());
                xpiwipeqOA2.setCr_path_ver_fk(prd.getCr_path_ver_fk());
                xpiwipeqOA2.setCr_tool_id_fk(prd.getCr_tool_id_fk());
                xpiwipeqOA2.setFab_sn(prd.getFab_sn());
                xpiwipeqOA2.setPep_lvl(bis_ope.getPep_lvl());
                xpiwipeqOA2.setWo_id(prd.getWo_id_fk());
                xpiwipeqOA2.setMdl_id_fk(prd.getMdl_id_fk());
                xpiwipeqOA2.setPrd_qty(prd.getPrd_qty());
                xpiwipeqOA2.setPrd_std_qty(prd.getPrd_std_qty());
                xpiwipeqOA2.setSht_ope_msg(prd.getSht_ope_msg());
                xpiwipeqOA2.setPrd_stat(prd.getPrd_stat());
                xpiwipeqOA2.setPv_prd_grade(prd.getPv_prd_grade());
                xpiwipeqOA2.setPrd_admin_flg(prd.getPrd_admin_flg());
                xpiwipeqOA2.setGroup_id(prd.getGroup_id());
                if (!Util.isSpaceCheck(gproc_flg)) {
                    xpiwipeqOA2.setProc_flg(gproc_flg);
                }
                //增加返工品标识
                if (!Util.isSpaceCheck(prd.getOqc_skip_flg())) {
                    xpiwipeqOA2.setOqc_skip_flg(prd.getOqc_skip_flg());
                }

                if (null != prd.getPrd_admin_flg()) {
                    StringBuffer prd_admin_flg_sb = new StringBuffer(prd.getPrd_admin_flg());
                    String ipqc_flg = "OK";
                    String th_judge_flg = "OK";
                    String fz_flg = "OK";
                    if (prd_admin_flg_sb.charAt(1) == 'Y') {
                        ipqc_flg = "NG";
                    } else if (prd_admin_flg_sb.charAt(1) == 'N') {
                        ipqc_flg = "OK";
                    } else if (prd_admin_flg_sb.charAt(1) == 'S') {
                        ipqc_flg = "SC";
                    } else {
                        ipqc_flg = "";
                    }
                    if (prd_admin_flg_sb.charAt(2) == 'Y') {
                        th_judge_flg = "NG";
                    } else if (prd_admin_flg_sb.charAt(2) == 'N') {
                        th_judge_flg = "OK";
                    } else {
                        th_judge_flg = "";
                    }
                    if (prd_admin_flg_sb.charAt(3) == 'Y') {
                        fz_flg = "NG";
                    } else if (prd_admin_flg_sb.charAt(3) == 'N') {
                        fz_flg = "OK";
                    } else {
                        fz_flg = "";
                    }
                    xpiwipeqOA2.setIpqc_flg(ipqc_flg);
                    xpiwipeqOA2.setTh_judge_flg(th_judge_flg);
                    xpiwipeqOA2.setFz_flg(fz_flg);
                } else {
                    xpiwipeqOA2.setIpqc_flg("");
                    xpiwipeqOA2.setTh_judge_flg("");
                    xpiwipeqOA2.setFz_flg("");
                }

                if (PROC_IN_PROCESS.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setBox_id(prd.getBox_id_fk());
                    xpiwipeqOA2.setPv_box_id_fk(prd.getPv_box_id_fk());
                } else if (PROC_WAIT.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setBox_id("");
                    xpiwipeqOA2.setPv_box_id_fk(prd.getBox_id_fk());
                }
                xpiwipeqOA2.setMtrl_box_id_fk(prd.getMtrl_box_id_fk());
                xpiwipeqOA2.setX_axis_cnt_fk(prd.getX_axis_cnt_fk());
                xpiwipeqOA2.setY_axis_cnt_fk(prd.getY_axis_cnt_fk());
                if (null != prd.getT_rubbing_time()) {
                    xpiwipeqOA2.setTft_buff_time(prd.getT_rubbing_time()
                            .toString());
                }
                if (null != prd.getC_rubbing_time()) {
                    xpiwipeqOA2.setCf_buff_time(prd.getC_rubbing_time()
                            .toString());
                }

                if (prd.getP1_timestamp() != null && PROC_IN_PROCESS.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setStart_time(prd.getP1_timestamp());
                    xpiwipeqOA2.setProcess_user(prd.getEvt_usr());
                    if (prd.getP2_timestamp() != null) {
                        xpiwipeqOA2.setEnd_user(prd.getEvt_usr());
                        xpiwipeqOA2.setEnd_time(prd.getP2_timestamp());
                    }
                }
                if (prd.getLogon_timestamp() != null && PROC_IN_PROCESS.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setLogon_usr(prd.getLogon_usr());
                    xpiwipeqOA2.setLogon_timestamp(prd.getLogon_timestamp());
                }
                if (prd.getLogof_timestamp() != null) {
                    xpiwipeqOA2.setLogof_usr(prd.getLogof_usr());
                    xpiwipeqOA2.setLogof_timestamp(prd.getLogof_timestamp());
                }
                oary_prd.add(xpiwipeqOA2);
            }
        }

        outTrx.setOary_prd(oary_prd);
        outTrx.setTbl_cnt(oary_prd.size());

        return lRc;
    }

    /**
     * 前台点击正常品、管控品、留滞品
     * 直接保存数据到数据库栏位：prd_grade
     * author：THY
     *
     * @return
     */
    private long updateJudgeGrade() {
        List<XpiwipeqIA> iary = inTrx.getIary();
        for (XpiwipeqIA xpiwipeqIA : iary) {
            String prd_grade = xpiwipeqIA.getPrd_grade();
            String prd_seq_id = xpiwipeqIA.getPrd_seq_id();

            Ret_prd_info prd = retPrdInfoDao.get(prd_seq_id);

            if (null == prd) {
                gszMsgBuf = "该产品[" + prd_seq_id + "]不存在";
                return E_RET_BOX + E_READ_NOT_FOUND;
            }
            prd.setPrd_grade(prd_grade);
            prd.setEvt_cate(EVT_PRD_GRADE_JUDGE);
            retPrdInfoDao.update(prd);
        }
        return _NORMAL;
    }

    private long queryBisData() {
        String ope_id = inTrx.getCr_ope_id();
        if (Util.isSpaceCheck(ope_id)) {
            return _NORMAL;
        }
        String ope_ver = "00000";
        Bis_opeId bis_opeId = new Bis_opeId();
        bis_opeId.setOpe_id(ope_id);
        bis_opeId.setOpe_ver(ope_ver);

        Bis_ope bis_ope = new Bis_ope();
        bis_ope = bisOpeDao.get(bis_opeId);

        String hql = "FROM Bis_data WHERE data_cate = 'PRST' AND data_id = '" + bis_ope.getProc_id() + "'";

        List<Bis_data> bisDataList = new ArrayList<Bis_data>();
        bisDataList = bisDataDao.find(hql);
        if (bisDataList.isEmpty()) {
            gszMsgBuf = "该站点[" + ope_id + "]制程段信息维护不全";
            return E_RET_BOX + E_READ_NOT_FOUND;
        }
        gproc_flg = bisDataList.get(0).getExt_4();
        return _NORMAL;
    }


    /**
     * 根据玻璃ID查询该来料箱中所有的玻璃
     * 如果是在制等待站点
     * 则需先检查该玻璃所在箱子是不是属于在制等待箱
     *
     * @return
     * @author THY
     */
    private long queryAllPrdListInBoxByShtId() {
        String prd_seq_id = inTrx.getPrd_id();
        String cr_ope_id = inTrx.getCr_ope_id();
        String cr_ope_ver = inTrx.getCr_ope_ver();
        String cr_proc_id = inTrx.getCr_proc_id();
        String check_flg = "";

        inTrx.setLot_id("");
        inTrx.setBox_id("");
        inTrx.setPv_box_id("");

        if (Util.isSpaceCheck(prd_seq_id)) {
            gszMsgBuf = "请输入产品ID";
            return E_RET_PRD_INFO + E_READ_NOT_FOUND;
        }

        Ret_prd_info ret_prd_info = new Ret_prd_info();
        ret_prd_info = retPrdInfoDao.get(prd_seq_id);

        if (ret_prd_info == null) {
            gszMsgBuf = "该产品ID[" + prd_seq_id + "]不存在";
            return E_RET_PRD_INFO + E_READ_NOT_FOUND;
        }

        if (PROC_WAIT.equals(ret_prd_info.getPrd_stat())) {
            if (!(cr_ope_id.equals(ret_prd_info.getNx_ope_id_fk())) ||
                    !(cr_ope_ver.equals(ret_prd_info.getNx_ope_ver_fk()))) {
                gszMsgBuf = "该产品ID[" + prd_seq_id + "]在[" + ret_prd_info.getNx_ope_id_fk() + "]站点";
                return E_RET_PRD_INFO + E_READ_NOT_FOUND;
            }
        }

        if (PROC_IN_PROCESS.equals(ret_prd_info.getPrd_stat())) {
            if (!(cr_ope_id.equals(ret_prd_info.getCr_ope_id_fk())) ||
                    !(cr_ope_ver.equals(ret_prd_info.getCr_ope_ver_fk()))) {
                gszMsgBuf = "该产品ID[" + prd_seq_id + "]不在[" + cr_ope_id + "]站点";
                return E_RET_PRD_INFO + E_READ_NOT_FOUND;
            }
        }

        long lRc = 1;
        String mtrl_box = ret_prd_info.getMtrl_box_id_fk();
        if (Util.isSpaceCheck(mtrl_box)) {
            gszMsgBuf = "该产品ID[" + prd_seq_id + "]来料箱为空";
            return E_RET_PRD_INFO + E_READ_NOT_FOUND;
        }
        Ret_wo ret_wo = retWoDao.get(ret_prd_info.getWo_id_fk());
        if (ret_wo == null) {
            gszMsgBuf = "该产品ID[" + prd_seq_id + "]的工单代码[" + ret_prd_info.getWo_id_fk() + "]不存在！";
            return E_RET_WO + E_READ_NOT_FOUND;
        }

        if (!Util.isSpaceCheck(ret_wo.getOpe_eff_flg()) && ret_wo.getOpe_eff_flg().equals("Y")) {
            check_flg = inTrx.getCheck_flg();
        } else {
            check_flg = "";
        }
        //非在制等待站点,直接返回所有玻璃
        if (Util.isSpaceCheck(check_flg)) {
            inTrx.setMtrl_box_id(mtrl_box);
            inTrx.setPrd_id("");
            lRc = queryPrdInfoByMtrlBox();
        } else {
            inTrx.setMtrl_box_id(mtrl_box);
            inTrx.setPrd_id("");
            if (inTrx.getCr_proc_id().equals("JBZJ") || inTrx.getCr_proc_id().equals("JBQA")) {
                lRc = getPrdWipWaitJBList();
            } else {
                lRc = getPrdWipWaitDMList();
            }
            if (lRc != _NORMAL) {
                return lRc;
            }
        }

        logger.info("prd_seq_id = " + prd_seq_id);
        logger.info("cr_ope_id = " + cr_ope_id);
        logger.info("cr_ope_ver = " + cr_ope_ver);
        logger.info("cr_proc_id = " + cr_proc_id);
        logger.info("check_flg = " + check_flg);
        return _NORMAL;
    }

    private long queryPrdInfoByMtrlBox() {
        long lRc = _NORMAL;

        // Get Pep_lvl
        Bis_ope bis_ope = new Bis_ope();
        Bis_opeId bis_opeId = new Bis_opeId();
        bis_opeId.setOpe_id(inTrx.getCr_ope_id());
        bis_opeId.setOpe_ver(inTrx.getCr_ope_ver());

        bis_ope = bisOpeDao.get(bis_opeId);
        if (null == bis_ope) {
            gszMsgBuf = new NotFoundRtnBeen(bis_opeId.toString(), Bis_ope.class)
                    .toString();
            return E_BIS_OPE + E_READ_NOT_FOUND;
        }

        // Get prd list
        List<Ret_prd_info> ret_prd_infoList = new ArrayList<Ret_prd_info>();

        String sql = "";

        if (!Util.isSpaceCheck(inTrx.getBox_id())) {
            sql = "FROM Ret_prd_info WHERE prd_stat='INPR' AND cr_ope_id_fk='"
                    + inTrx.getCr_ope_id()
                    + "' AND cr_ope_ver_fk = '"
                    + inTrx.getCr_ope_ver()
                    + "' AND box_id_fk='"
                    + inTrx.getBox_id() + "'";
        } else if (!Util.isSpaceCheck(inTrx.getPv_box_id())) {
            sql = "FROM Ret_prd_info WHERE ((prd_stat='INPR' AND cr_ope_id_fk='"
                    + inTrx.getCr_ope_id()
                    + "' AND cr_ope_ver_fk = '"
                    + inTrx.getCr_ope_ver()
                    + "' AND pv_box_id_fk='" + inTrx.getPv_box_id()
                    + "') or (prd_stat='WAIT' AND nx_ope_id_fk='"
                    + inTrx.getCr_ope_id()
                    + "' AND nx_ope_ver_fk = '"
                    + inTrx.getCr_ope_ver()
                    + "' AND box_id_fk='" + inTrx.getPv_box_id() + "'))";
        } else {
            sql = "FROM Ret_prd_info WHERE ((prd_stat='INPR' AND cr_ope_id_fk='"
                    + inTrx.getCr_ope_id()
                    + "' AND cr_ope_ver_fk = '"
                    + inTrx.getCr_ope_ver()
                    + "') or (prd_stat='WAIT' AND nx_ope_id_fk='"
                    + inTrx.getCr_ope_id()
                    + "' AND nx_ope_ver_fk = '"
                    + inTrx.getCr_ope_ver() + "'))";
        }
        sql = sql + " AND mtrl_box_id_fk='" + inTrx.getMtrl_box_id() + "'";
        sql = sql + " ORDER BY box_id_fk,pv_box_id_fk, convert(slot_no,UNSIGNED) ";

        ret_prd_infoList = retPrdInfoDao.find(sql);
        outTrx.setTbl_cnt(0);
        if (!ret_prd_infoList.isEmpty()) {
            List<XpiwipeqOA2> oary_prd = new ArrayList<XpiwipeqOA2>();
            for (Ret_prd_info prd : ret_prd_infoList) {
                XpiwipeqOA2 xpiwipeqOA2 = new XpiwipeqOA2();
                Ret_wo ret_wo = retWoDao.get(prd.getWo_id_fk());
                if (ret_wo == null) {
                    xpiwipeqOA2.setCus_id("");
                } else {
                    xpiwipeqOA2.setCus_id(ret_wo.getCus_id_fk());
                }
                xpiwipeqOA2.setPrd_seq_id(prd.getPrd_seq_id());
                xpiwipeqOA2.setSlot_no(prd.getSlot_no());
                xpiwipeqOA2.setMtrl_slot_no_fk(prd.getMtrl_slot_no_fk());
                xpiwipeqOA2.setEvt_timestamp(prd.getEvt_timestamp().toString());
                xpiwipeqOA2.setEvt_user(prd.getEvt_usr());
                xpiwipeqOA2.setLot_id(prd.getLot_id());
                if (PROC_IN_PROCESS.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setPrd_grade(prd.getPrd_grade());
                } else {
                    xpiwipeqOA2.setPrd_grade(_SPACE);
                }
                xpiwipeqOA2.setCr_proc(prd.getCr_proc_id_fk());
                xpiwipeqOA2.setCr_ope_id(prd.getCr_ope_id_fk());
                xpiwipeqOA2.setCr_ope_no_fk(prd.getCr_ope_no_fk());
                xpiwipeqOA2.setCr_ope_ver_fk(prd.getCr_ope_ver_fk());
                xpiwipeqOA2.setCr_path_id_fk(prd.getCr_path_id_fk());
                xpiwipeqOA2.setCr_path_ver_fk(prd.getCr_path_ver_fk());
                xpiwipeqOA2.setCr_tool_id_fk(prd.getCr_tool_id_fk());
                xpiwipeqOA2.setFab_sn(prd.getFab_sn());
                xpiwipeqOA2.setPep_lvl(bis_ope.getPep_lvl());
                xpiwipeqOA2.setWo_id(prd.getWo_id_fk());
                xpiwipeqOA2.setMdl_id_fk(prd.getMdl_id_fk());
                xpiwipeqOA2.setPrd_qty(prd.getPrd_qty());
                xpiwipeqOA2.setPrd_std_qty(prd.getPrd_std_qty());
                xpiwipeqOA2.setSht_ope_msg(prd.getSht_ope_msg());
                xpiwipeqOA2.setPrd_stat(prd.getPrd_stat());
                xpiwipeqOA2.setPv_prd_grade(prd.getPv_prd_grade());
                xpiwipeqOA2.setDs_recipe_id(prd.getDs_recipe_id());
                xpiwipeqOA2.setGroup_id(prd.getGroup_id());
                if (!Util.isSpaceCheck(gproc_flg)) {
                    xpiwipeqOA2.setProc_flg(gproc_flg);
                }
                //增加返工品标识
                if (!Util.isSpaceCheck(prd.getOqc_skip_flg())) {
                    xpiwipeqOA2.setOqc_skip_flg(prd.getOqc_skip_flg());
                }

                xpiwipeqOA2.setPrd_admin_flg(prd.getPrd_admin_flg());
                if (null != prd.getPrd_admin_flg()) {
                    StringBuffer prd_admin_flg_sb = new StringBuffer(prd.getPrd_admin_flg());
                    String ipqc_flg = "OK";
                    String th_judge_flg = "OK";
                    String fz_flg = "OK";
                    if (prd_admin_flg_sb.charAt(1) == 'Y') {
                        ipqc_flg = "NG";
                    } else if (prd_admin_flg_sb.charAt(1) == 'N') {
                        ipqc_flg = "OK";
                    } else if (prd_admin_flg_sb.charAt(1) == 'S') {
                        ipqc_flg = "SC";
                    } else {
                        ipqc_flg = "";
                    }
                    if (prd_admin_flg_sb.charAt(2) == 'Y') {
                        th_judge_flg = "NG";
                    } else if (prd_admin_flg_sb.charAt(2) == 'N') {
                        th_judge_flg = "OK";
                    } else {
                        th_judge_flg = "";
                    }
                    if (prd_admin_flg_sb.charAt(3) == 'Y') {
                        fz_flg = "NG";
                    } else if (prd_admin_flg_sb.charAt(3) == 'N') {
                        fz_flg = "OK";
                    } else {
                        fz_flg = "";
                    }
                    xpiwipeqOA2.setIpqc_flg(ipqc_flg);
                    xpiwipeqOA2.setTh_judge_flg(th_judge_flg);
                    xpiwipeqOA2.setFz_flg(fz_flg);
                } else {
                    xpiwipeqOA2.setIpqc_flg("");
                    xpiwipeqOA2.setTh_judge_flg("");
                    xpiwipeqOA2.setFz_flg("");
                }

                if (PROC_IN_PROCESS.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setBox_id(prd.getBox_id_fk());
                    xpiwipeqOA2.setPv_box_id_fk(prd.getPv_box_id_fk());
                } else if (PROC_WAIT.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setBox_id("");
                    xpiwipeqOA2.setPv_box_id_fk(prd.getBox_id_fk());
                }
                xpiwipeqOA2.setMtrl_box_id_fk(prd.getMtrl_box_id_fk());
                xpiwipeqOA2.setX_axis_cnt_fk(prd.getX_axis_cnt_fk());
                xpiwipeqOA2.setY_axis_cnt_fk(prd.getY_axis_cnt_fk());
                if (null != prd.getT_rubbing_time()) {
                    xpiwipeqOA2.setTft_buff_time(prd.getT_rubbing_time()
                            .toString());
                }
                if (null != prd.getC_rubbing_time()) {
                    xpiwipeqOA2.setCf_buff_time(prd.getC_rubbing_time()
                            .toString());
                }

                if (prd.getP1_timestamp() != null && PROC_IN_PROCESS.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setStart_time(prd.getP1_timestamp());
                    xpiwipeqOA2.setProcess_user(prd.getEvt_usr());
                    if (prd.getP2_timestamp() != null) {
                        xpiwipeqOA2.setEnd_user(prd.getEvt_usr());
                        xpiwipeqOA2.setEnd_time(prd.getP2_timestamp());
                    }
                }
                if (prd.getLogon_timestamp() != null && PROC_IN_PROCESS.equals(prd.getPrd_stat())) {
                    xpiwipeqOA2.setLogon_usr(prd.getLogon_usr());
                    xpiwipeqOA2.setLogon_timestamp(prd.getLogon_timestamp());
                }
                if (prd.getLogof_timestamp() != null) {
                    xpiwipeqOA2.setLogof_usr(prd.getLogof_usr());
                    xpiwipeqOA2.setLogof_timestamp(prd.getLogof_timestamp());
                }

                oary_prd.add(xpiwipeqOA2);
            }
            outTrx.setOary_prd(oary_prd);
            outTrx.setTbl_cnt(oary_prd.size());
        }

        return lRc;
    }

    private long getPrdWipList() {
        long lRc = _NORMAL;
        Ret_wo ret_wo = new Ret_wo();
        String woId = "";
        if (inTrx.getWo_id() != null) {//根据工单查询
            woId = inTrx.getWo_id();
        } else if (inTrx.getLot_id() != null) {//根据批次查询
            Ret_prd_lot ret_prd_lot = new Ret_prd_lot();
            Ret_prd_lotId ret_prd_lotId = new Ret_prd_lotId();
            ret_prd_lotId.setLot_id(inTrx.getLot_id());
            ret_prd_lotId.setLot_splt_id(LOT_SPLIT_0);
            ret_prd_lot = retPrdLotDao.get(ret_prd_lotId);
            woId = ret_prd_lot.getWo_id_fk();
        } else if (inTrx.getMtrl_box_id() != null) {//根据来料箱号查询
            List<Ret_prd_in> retPrdInList = new ArrayList<Ret_prd_in>();
            String sql = "FROM Ret_prd_in WHERE MTRL_BOX_ID='" + inTrx.getMtrl_box_id() + "'";
            retPrdInList = retPrdInDao.find(sql);
            if (retPrdInList.size() > 0) {
                woId = retPrdInList.get(0).getWo_id_fk();
            }
        } else if (inTrx.getBox_id() != null) {//根据转入箱号查询
            List<Ret_prd_info> retPrdList = new ArrayList<Ret_prd_info>();
            String sql = "FROM Ret_prd_info WHERE BOX_ID_FK='" + inTrx.getBox_id() + "'";
            retPrdList = retPrdInfoDao.find(sql);
            if (retPrdList.size() > 0) {
                woId = retPrdList.get(0).getWo_id_fk();
            }
        } else if (inTrx.getPv_box_id() != null) {//根据入账箱号查询
            List<Ret_prd_info> retPrdList = new ArrayList<Ret_prd_info>();
            String sql = "FROM Ret_prd_info WHERE PV_BOX_ID_FK='" + inTrx.getPv_box_id() + "'";
            retPrdList = retPrdInfoDao.find(sql);
            if (retPrdList.size() > 0) {
                woId = retPrdList.get(0).getWo_id_fk();
            }
        }

        System.out.println(woId);
        if (Util.isSpaceCheck(woId)) {
            lRc = getPrdList();
        } else {
            ret_wo = retWoDao.get(woId);
            System.out.println(ret_wo.getOpe_eff_flg());
            if (ret_wo.getOpe_eff_flg().equals("Y")) {//原箱返
                if (inTrx.getCr_proc_id().equals("JBZJ") || inTrx.getCr_proc_id().equals("JBQA")) {
                    lRc = getPrdWipWaitJBList();
                } else {
                    lRc = getPrdWipWaitDMList();
                }
            } else {//非原箱返
                lRc = getPrdList();
            }
        }
        return lRc;
    }
}
